jsp就是不能向mysql不能添加记录?
程序如下:<%@pagecontentType="text/html;charset=gbk"language="java"import="java.sql.*,java...
程序如下:
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*,java.io.*" errorPage="" %>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:8080/jjm_geho?user=root&password=12345678&characterEncoding=GBK";
Connection cons= DriverManager.getConnection(url);
Statement stmta = cons.createStatement();
String mjb1 = "123";
String mjb2 = "测试";
String kas9 = "insert into jkas(as1,as2) values('"+mjb1+"','"+mjb2+"')";
stmta.executeUpdate(kas9);
//以上cons连接做数据查询是正常的,就是不能插入。
//查询是正常的如下:
Statement stmt=cons.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String jsyi02="select * from jkas ";
ResultSet rst02=stmt.executeQuery(jsyi02);
rst02.first();
while(rst.next())
{
out.println(rst02.getString("as1")+":"+rst02.getString("as2")+"<br />");
}
%>
请各位高手指点,让我能添加数据成功,另外还有加分。mysql字符是GBK。 展开
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*,java.io.*" errorPage="" %>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:8080/jjm_geho?user=root&password=12345678&characterEncoding=GBK";
Connection cons= DriverManager.getConnection(url);
Statement stmta = cons.createStatement();
String mjb1 = "123";
String mjb2 = "测试";
String kas9 = "insert into jkas(as1,as2) values('"+mjb1+"','"+mjb2+"')";
stmta.executeUpdate(kas9);
//以上cons连接做数据查询是正常的,就是不能插入。
//查询是正常的如下:
Statement stmt=cons.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String jsyi02="select * from jkas ";
ResultSet rst02=stmt.executeQuery(jsyi02);
rst02.first();
while(rst.next())
{
out.println(rst02.getString("as1")+":"+rst02.getString("as2")+"<br />");
}
%>
请各位高手指点,让我能添加数据成功,另外还有加分。mysql字符是GBK。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询