The database was moved on MySQL a few days ago, and Mysql5.0 has been improved during the transfer process. Really don't know, I am scared! However, mysql's Chinese issue is still very big, but in the end, we will always have a better solution. First, the web server uses RESIN, the operating system adopts the Windows series, connects the database to use the data source mode. Add the following code (located between
Second, use the following code to establish a connection when connecting the database:
Context env = new initialContext ();
DataSource pool = (DataSource) Env.lookup ("java: comp / env / jdbc / erms"); if (pool == null) Throw new Exception ("JDBC / Erms IS An Unknown Datasource); conn = pool.getConnection (); STMT = conn.createstatement ();
Third, write the following two static methods:
public static String getstr (String str) {try {String temp_p = str; byte [] temp_t = temp_p.getBytes ( "ISO8859-1"); String temp = new String (temp_t); return temp;} catch (UnsupportedEncodingException ex) {System.out.println (ex); return ";
}
Public static string isoconverter (string str) {if (str == null) {str = "";} else {try {str = new string (Str.getbytes ("GBK"), "ISO8859_1");} catch (Exception EX) {EX.PrintStackTrace ();}} Return Str;} Before executing a SQL statement, execute the ISOCONVERTER (SQL) method for the SQL statement to be executed, you can write the Chinese normal write mysql (in mysql is Chinese You can use a third-party tool to view); after removing data from the database, you can get the true Chinese string using the GetStr (CNSTRING) method. It should be noted that mysql does not need any other settings. In addition to the two points indicated above, there is no other place to convert character encoding.
Mysql5.0 and corresponding JDBC can be downloaded at http://dev.mysql.com/downloads.