网站的jsp页面怎么连接数据库啊
1个回答
展开全部
加载驱动 新建连接 建立状态 操作 update close
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
boolean flag=false;
%>
<%
String UID=request.getParameter("UID");
String psw=request.getParameter("psw");
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPSW);
String sql="SELECT UID,psw FROM student WHERE UID=? AND psw=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,UID);
pstmt.setString(2,psw);
rs=pstmt.executeQuery();
if(rs.next()){
flag=true;
}
}catch(Exception e){ out.println(e.toString());
}finally{
try{
conn.close();
}catch(Exception e){ out.println(e.toString());
}
}
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
boolean flag=false;
%>
<%
String UID=request.getParameter("UID");
String psw=request.getParameter("psw");
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPSW);
String sql="SELECT UID,psw FROM student WHERE UID=? AND psw=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,UID);
pstmt.setString(2,psw);
rs=pstmt.executeQuery();
if(rs.next()){
flag=true;
}
}catch(Exception e){ out.println(e.toString());
}finally{
try{
conn.close();
}catch(Exception e){ out.println(e.toString());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询