Home > Database > Mysql Tutorial > jsp操作mysql数据库的问题

jsp操作mysql数据库的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 09:45:39
Original
905 people have browsed it

mysqljsp数据库连接

我是想做一个什么事呢:就是在jsp里用statement的executeQuery(string)来向数据库增加数据,数据库为hanshuangwu,表为infor,其中只有两个属性:id、name。执行下面的代码后,显示在“****”标记的代码处有“Unknown column 'idString' in 'field list' ”错误,菜鸟求解,请高手不吝赐教啊^_^

pageEncoding="GB18030" import="java.sql.*"%>





连接数据库

连接数据库库

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();
%>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template