/**
*
*
* @param date
* @return String
*/
public static String dateToStr(java.util.Date date)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = sdf.format(date);
return str;
}
/**
*
*
* @param n
* @return boolean
*/
public static boolean isPrimes(int n)
{
for (int i = 2; i <= Math.sqrt(n); i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
/**
* byte 16
*
* @param hint
* String
* @param b
* byte[]
* @return void
*/
public static void printHexString(String hint, byte[] b)
{
System.out.print(hint);
for (int i = 0; i < b.length; i++)
{
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1)
{
hex = '0' + hex;
}
System.out.print(hex.toUpperCase() + " ");
}
System.out.println("");
}
/**
*
*
* @param value
* @return String
*/
public static String hangeToBig(double value)
{
char[] hunit = { ' ', ' ', ' ' }; //
char[] vunit = { ' ', ' ' }; //
char[] digit = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }; //
long midVal = (long) (value * 100); //
String valStr = String.valueOf(midVal); //
String head = valStr.substring(0, valStr.length() - 2); //
String rail = valStr.substring(valStr.length() - 2); //
String prefix = ""; //
String suffix = ""; //
//
if (rail.equals("00"))
{ // 0
suffix = " ";
}
else
{
suffix = digit[rail.charAt(0) - '0'] + " " + digit[rail.charAt(1) - '0'] + " "; //
}
//
char[] chDig = head.toCharArray(); //
char zero = '0'; // '0' 0
byte zeroSerNum = 0; // 0
for (int i = 0; i < chDig.length; i++)
{ //
int idx = (chDig.length - i - 1) % 4; //
int vidx = (chDig.length - i - 1) / 4; //
if (chDig[i] == '0')
{ // 0
zeroSerNum++; // 0
if (zero == '0')
{ //
zero = digit[0];
}
else if (idx == 0 && vidx > 0 && zeroSerNum < 4)
{
prefix += vunit[vidx - 1];
zero = '0';
}
continue;
}
zeroSerNum = 0; // 0
if (zero != '0')
{ // 0, , ,
prefix += zero;
zero = '0';
}
prefix += digit[chDig[i] - '0']; //
if (idx > 0)
prefix += hunit[idx - 1];
if (idx == 0 && vidx > 0)
{
prefix += vunit[vidx - 1]; // ,
}
}
if (prefix.length() > 0)
prefix += ' '; // ,
return prefix + suffix; //
}
/**
*
*
* @param QJStr
* @return String
*/
public static final String QJToBJChange(String QJStr)
{
char[] chr = QJStr.toCharArray();
String str = "";
for (int i = 0; i < chr.length; i++)
{
chr[i] = (char) ((int) chr[i] - 65248);
str += chr[i];
}
return str;
}
/**
*
* @param obj
* @return
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws SecurityException
* @throws IllegalArgumentException
*/
@SuppressWarnings("unchecked")
public static Object copy(Object obj) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException
{
//
Class classType = obj.getClass();
// ,getConstructor
Object objectCopy = classType.getConstructor(new Class[]{}).newInstance(new Object[]{});
//
Field[] fields = classType.getDeclaredFields();
for(int i = 0; i < fields.length; i++)
{
//
Field field = fields[i];
String fieldName = field.getName();
String stringLetter = fieldName.substring(0, 1).toUpperCase();
// getXXX setXXX
String getName = "get" + stringLetter + fieldName.substring(1);
String setName = "set" + stringLetter + fieldName.substring(1);
//
Method getMethod = classType.getMethod(getName, new Class[]{});
Method setMethod = classType.getMethod(setName, new Class[]{field.getType()});
// getXXX()
Object value = getMethod.invoke(obj, new Object[]{});
// setXXX()
setMethod.invoke(objectCopy, new Object[]{value});
}
return objectCopy;
}
MySQL:
String Driver="com.mysql.jdbc.Driver"; //
String URL="jdbc:mysql://localhost:3306/db_name"; // URL,db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).new Instance();
Connection con=DriverManager.getConnection(URL,Username,Password);
Microsoft SQL Server 2.0 (3 jar ):
String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; // SQL
String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).new Instance(); //
Connection con=DriverManager.getConnection(URL,UserName,Password); //
Microsoft SQL Server 3.0 (1 jar ): //
String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; // SQL
String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).new Instance(); //
Connection con=DriverManager.getConnection(URL,UserName,Password); //
Sysbase:
String Driver="com.sybase.jdbc.SybDriver"; //
String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
Oracle( thin ):
String Driver="oracle.jdbc.driver.OracleDriver"; //
String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl SID
String Username="username"; //
String Password="password"; //
Class.forName(Driver).newInstance(); //
Connection con=DriverManager.getConnection(URL,Username,Password);
PostgreSQL:
String Driver="org.postgresql.Driver"; //
String URL="jdbc:postgresql://localhost/db_name"; //db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
DB2:
String Driver="com.ibm.db2.jdbc.app.DB2.Driver"; // DB2 Provider
//String Driver="com.ibm.db2.jdbc.net.DB2.Driver"; // DB2 Provider
String URL="jdbc:db2://localhost:5000/db_name"; //db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
Informix:
String Driver="com.informix.jdbc.IfxDriver";
String URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver"; //db_name
String Username="username"; //
String Password="password"; //
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);
JDBC-ODBC:
String Driver="sun.jdbc.odbc.JdbcOdbcDriver";
String URL="jdbc:odbc:dbsource"; //dbsource
String Username="username"; //
String Password="password"; //
Class.forName(Driver).newInstance();
Connection con=DriverManager.getConnection(URL,Username,Password);