JSP+MySql我的数据库只能插入一行,为什么以后就无法插入
这是jsp代码<%finalStringDBDRIVER="com.mysql.jdbc.Driver";finalStringDBURL="jdbc:mysql://l...
这是jsp代码
<%
final String DBDRIVER="com.mysql.jdbc.Driver";
final String DBURL="jdbc:mysql://localhost:3306/wangzhan";
final String DBUSER="root";
final String DBPASSWORD="999999";
Connection conn =null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql =null;
%>
<%
try{
sql="insert into mytable VALUES(?,?)";
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,password);
pstmt.executeUpdate();
out.println("<br><br><b>insert successful</b>");
//rs.close();
pstmt.close();
conn.close();
}
catch(Exception e)
{out.println(e);}
%>
这是数据库语句
create table mytable ( username varchar(20),password varchar(20),email varchar(20)); 展开
<%
final String DBDRIVER="com.mysql.jdbc.Driver";
final String DBURL="jdbc:mysql://localhost:3306/wangzhan";
final String DBUSER="root";
final String DBPASSWORD="999999";
Connection conn =null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql =null;
%>
<%
try{
sql="insert into mytable VALUES(?,?)";
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,password);
pstmt.executeUpdate();
out.println("<br><br><b>insert successful</b>");
//rs.close();
pstmt.close();
conn.close();
}
catch(Exception e)
{out.println(e);}
%>
这是数据库语句
create table mytable ( username varchar(20),password varchar(20),email varchar(20)); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询