Js|mysql
Premise:
Place the MySQL database driver in the Web-inf\lib directory of the working directory (so you can link to the JSP)
With a JavaBean connection, the compiled. class file is placed under the classes file, and if the file contains package instructions, it is placed in the
Under the specified directory.
At this point, there is no problem with the data query, but Update,delete and insert are not valid. (feasible in SQL Server)
Problem resolution, see JDK Description, Find statement method segment ResultSet executequery (string), int executeupdate (string)
Modify JavaBean, add Executeupdate method, modify. jsp file, point to Executeupdate when not select, test Update,insert,
Delete is successfully implemented
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 instructioncount;
}
New problem: When MySQL uses utf-8 to support all Chinese, the decoding of the payment string will destroy the Chinese input.
When inserting and updating data, cancel the original encoding with the GBK new String
Author