贵阳最火的休闲会所:连接数据库测试有误,代码如下.请各位指点.

来源:百度文库 编辑:高校问答 时间:2024/05/05 16:48:26
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import = "com.DealString.DealString"%>
<jsp:useBean id="dealString" scope="page" class="com.DealString.DealString"></jsp:useBean>

<%
try{
Class.forName("com.mysql.jdbc.Driver");
}catch (Exception ex){
out.println(ex.toString());
}
//获取数据库连接
Connection conn = null;
try{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/room?user=root&password=123&useUnicode=true&characterEncoding=gb2312");
}catch (SQLException ex){
out.println(ex.toString());
}
%>
<%java.sql.PreparedStatement pstmt = null;
if(conn != null)
{
String sql = "insert Into userinfo(username,realname,passwd,repassword,sex,email,province,city,tel,mob,adress,role,onrole) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,realname);
pstmt.setString(3,passwd);
pstmt.setString(4,repassword);
pstmt.setString(5,email);
pstmt.setString(6,sex);
pstmt.setString(7,tel);
pstmt.setString(8,mob);
pstmt.setString(9,province);
pstmt.setString(10,city);
pstmt.setString(11,adress);
pstmt.setString(12,onrole);
pstmt.setString(13,role);

pstmt.execute(); //执行sql
ResultSet rst = pstmt.executeQuery( "Select * from userinfo");

while(rst.next())
{
username = rst.getString("username");
realname = rst.getString("realname");
passwd = rst.getString("passwd");
repassword = rst.getString("repassword");
sex =rst.getString("sex");

tel = rst.getString("tel");
mob = rst.getString("mob");
email = rst.getString("email");
province = rst.getString("province");
city = rst.getString("city");

role = rst.getString("role");
onrole = rst.getString("onrole");

}
pstmt.close();

}

conn.close();
%><%out.print("操作成功");%>

<html>
<head>

<title></title>
</head>

<body>
</body>
</html>

把错误提示贴出来