What do I want to do? use statement executeQuery (string) in jsp to add data to the database. the database is hanshuangwu and the table is infor. there are only two attributes: id and name. After the following code is executed, "Unknowncolumn & #39; idString & #39; in & #39; fieldlist & #39; is displayed in the code marked; "Error. Cainiao can solve the problem. please kindly advise ^_^ & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDHT mysqljsp database connection
What do I want to do? use statement executeQuery (string) in jsp to add data to the database. the database is hanshuangwu and the table is infor. there are only two attributes: id and name. After the following code is executed, the "Unknown column 'idstring' in 'Field list'" error is displayed in the code marked by "***". Cainiao can solve the problem, please kindly advise me! ^_^
<% @ Page import = "javax. servlet. jsp. tagext. TryCatchFinally" %>
<% @ Page language = "java" contentType = "text/html; charset = GB18030"
PageEncoding = "GB18030" import = "java. SQL. *" %>
<% Request. setCharacterEncoding ("gb2312"); %>
Connect to database
Connect to database
<%
Int idString = 1;
String nameString = "haha ";
String driverClass = "com. mysql. jdbc. Driver ";
String url = "jdbc: mysql: // localhost: 3306/hanshuangwu ";
String username = "root ";
String password = "161006 ";
Try {
Class. forName (driverClass );
} Catch (ClassNotFoundException e ){
System. out. println ("An exception occurred when loading the database driver (not a failure !) The content is as follows :");
E. printStackTrace ();
}
Connection con = DriverManager. getConnection (url, username, password );
Statement stmt = con. createStatement ();
***** Int rtn1_stmt.exe cuteUpdate ("insert into infor (id, name) values (idString, nameString )");****
ResultSet rs = stmt.exe cuteQuery ("select * from infor ");
Rs. next ();
While (rs. next ()){
Out. println ("id:" + rs. getInt (1) + "name:" + rs. getString (2 ));
}
Rs. close ();
Stmt. close ();
Con. close ();
%>