时间:2021-07-01 10:21:17 帮助过:26人阅读
我是想做一个什么事呢:就是在jsp里用statement的executeQuery(string)来向数据库增加数据,数据库为hanshuangwu,表为infor,其中只有两个属性:id、name。执行下面的代码后,显示在“****”标记的代码处有“Unknown column 'idString' in 'field list' ”错误,菜鸟求解,请高手不吝赐教啊^_^
<%@page import="javax.servlet.jsp.tagext.TryCatchFinally"%>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030" import="java.sql.*"%>
<% request.setCharacterEncoding("gb2312"); %>
<%
int idString=1;
String nameString="呵呵";
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("加载数据库驱动程序时异常(不就是失败嘛!)内容如下:");
e.printStackTrace();
}
Connection con=DriverManager.getConnection(url, username, password);
Statement stmt=con.createStatement();
****int rtn=stmt.executeUpdate("insert into infor(id,name) values(idString,nameString)");****
ResultSet rs = stmt.executeQuery("select * from infor ");
rs.next();
while(rs.next() ){
out.println("id:"+rs.getInt(1)+"name:"+rs.getString(2));
}
rs.close();
stmt.close();
con.close();
%>