Question about jsp operations on mysql database

Source: Internet
Author: User
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 ();
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.