premise:
Place the mysql database in the web-inf / lib directory of the working directory (this can be connected in JSP)
With the JavaBean connection, you will be compiled. Class file is placed under the class file. If the file contains the package command, put it.
Under the specified directory.
At this point, the data query is no problem, but Update, Delete and INSERT are invalid. (Viable in SQL Server)
Problem resolution, check the JDK instructions, find the method of Statement ResultSet ExecuteQuery (String), int executeUpdate (String)
Modify JavaBean, add an ExecuteUpdate method, modify the .jsp file, point to ExecuteUpdate when you do not select, Test Update, Insert,
DELETE is successful
EXECUTEQUERY method code:
public ResultSet executeQuery (String sqlString) {rs = null; try {conn = DriverManager.getConnection (connURL, userName, pwd); Statement stmt = conn.createStatement (); rs = stmt.executeQuery (sqlString);} catch (SQLException ex ) {System.err.println ("AQ.ExecuteQuery:" EX.GETMESSAGE ();} Return Rs;}
ExcuteUpdate method code:
public int executeUpdate (String sqlString) {instructionCount = 0; try {conn = DriverManager.getConnection (connURL, userName, pwd); Statement stmt = conn.createStatement (); stmt.executeUpdate (sqlString); instructionCount = 1;} catch ( Sqlexception ex) {system.err.println ("Aq.executeQuery:" EX.GETMESSAGE ());} Return INSTRUCTION;
New problem: When using UTF-8 in MySQL, the payment string will be coded again to destroy the Chinese input.
When inserting and updating data, cancel the original use of GBK's New String to encode