在jsp页面中向Mysql中插入怎么不成功?
<%@pagelanguage="java"import="java.util.*,java.sql.*,com.mysql.jdbc.Driver"pageEncodi...
<%@ page language="java" import="java.util.*,java.sql.*,com.mysql.jdbc.Driver" pageEncoding="utf-8"%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String user = "张三";
String number = "090514258";
String gender = "男";
String brithday = "1989-03-11";
String time = "2009";
String xibu = "信息工程系";
String banji = "二班";
String call = "1392568792";
String mail = "ch_bj2010@sina.com";
String qq = "1256900177";
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/class?user=root&password=admin");
String sql = "insert into student (user,number,gender,brithday,time,xibu,banji,call,mail,qq ) values(?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user);
pstmt.setString(2, number);
pstmt.setString(3, gender);
pstmt.setString(4, brithday);
pstmt.setString(5, time);
pstmt.setString(6, xibu);
pstmt.setString(7, banji);
pstmt.setString(8, call);
pstmt.setString(9, mail);
pstmt.setString(10, qq);
pstmt.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null){
try{
rs.close();
}catch(Exception e){
System.out.println("rs关闭失败!");
}
}
if(pstmt != null){
try{
pstmt.close();
}catch(Exception e){
System.out.println("stmt关闭失败!");
}
}
if(conn != null){
try{
conn.close();
}catch(Exception e){
System.out.println("conn关闭失败!");
}
}
}
%>
这个我实验啦、如果插入的是两条信息,能够添加成功,但是如果超过三条那么就插入失败!高手请指点一下是什么问题。谢谢啦!
那个数据库都是用的String 类型,没有其他类型。 展开
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String user = "张三";
String number = "090514258";
String gender = "男";
String brithday = "1989-03-11";
String time = "2009";
String xibu = "信息工程系";
String banji = "二班";
String call = "1392568792";
String mail = "ch_bj2010@sina.com";
String qq = "1256900177";
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/class?user=root&password=admin");
String sql = "insert into student (user,number,gender,brithday,time,xibu,banji,call,mail,qq ) values(?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user);
pstmt.setString(2, number);
pstmt.setString(3, gender);
pstmt.setString(4, brithday);
pstmt.setString(5, time);
pstmt.setString(6, xibu);
pstmt.setString(7, banji);
pstmt.setString(8, call);
pstmt.setString(9, mail);
pstmt.setString(10, qq);
pstmt.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null){
try{
rs.close();
}catch(Exception e){
System.out.println("rs关闭失败!");
}
}
if(pstmt != null){
try{
pstmt.close();
}catch(Exception e){
System.out.println("stmt关闭失败!");
}
}
if(conn != null){
try{
conn.close();
}catch(Exception e){
System.out.println("conn关闭失败!");
}
}
}
%>
这个我实验啦、如果插入的是两条信息,能够添加成功,但是如果超过三条那么就插入失败!高手请指点一下是什么问题。谢谢啦!
那个数据库都是用的String 类型,没有其他类型。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询