Mysql4.1.7 Chinese solution

xiaoxiao2021-03-06  59

Database: mysql4.1.7

JDBC: MySQL-Connector-Java-3.0.16-Ga-bin.jar

Test environment: Win2000sp4

1) Modify the My.ini file, join under [Client]: default-character-set = GBK (this sentence is not available), then add: default-character-set = GBK under the [MySQLD] item.

2) Restart the database, use the show global variables command to log in to change the variable to GBK

3) Establish a corresponding table

4) This is in the Java program:

String url = "jdbc: mysql: // localhost / test"; //? Useunicode = true & characterencoding = GBK

String User = "root";

String password = "mysqlroot";

String Inserttestencoding = "Insert Test123 Values ​​(3, 'Hello",' This is a Java client ') ";

Class.Forname ("org.gjt.mm.mysql.driver");

Con = DriverManager.getConnection (URL, User, Password);

STMT = con.createstatement ();

Stmt.execute (InsertTestenCoding);

System.out.println ("ID:" rgetstring ("id") "name:" rs.getstring ("name") "Address:" gtstring ("address"));

5) The only defect is that when you enter MySQL under Commond Line, it is garbled, but it is normally shown in MySQL Control Center.

6) Use in JSP:

<% @ Page ContentType = "text / html; charset = GB2312"%>

<% Class.forname ("org.gjt.mm.mysql.driver"). NewInstance ();

String url = "JDBC: mysql: // localhost / test? User = root & password = mysqlroot";

Connection conn = drivermanager.getConnection (URL);

Statement Stmt = conn.createstatement ();

String SQL = "SELECT * from test123";

String Sqlinsert = "Insert INTO TEST123 VALUES (15, 'Hello', 'JSP Page')"

Stmt.executeUpdate (Sqlinsert);

ResultSet RS = Stmt.executeQuery (SQL);

While (rs.next ()) {%>

Your first field content is: <% = rs.getstring (1)%> Your second field content is: <% = rs.getstring (2)%>

<%}%>

<% out.print ("Database Operation, Congratulations on You / N");%>

<% rs.close ();

Stmt.close ();

CONN.CLOSE ();

%>

转载请注明原文地址:https://www.9cbs.com/read-84253.html

New Post(0)