JSP如何查询数据库,如何把数据写到客户端?会写程序,如用户名和密码的验证( 回答者请写代码)
3个回答
展开全部
<%@page import="java.sql.*"%>
<%
String sql =“select * from test”;
Connection conn = null;
PreparedStatement ps =null;
ResultSet rs = null;
try {
String _dbUrl="jdbc:jtds:sqlserver://192.168.0.2:1433;DatabaseName=test;user=test;password=123;";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(_dbUrl);
ps =conn.prepareStatement(sql);
rs =ps.executeQuery();
while(rs.next()){
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
if(rs != null){
rs.close();
}
if(ps != null){
ps.close();
}
if(conn != null){
conn.close();
}
}
%>
<%
String sql =“select * from test”;
Connection conn = null;
PreparedStatement ps =null;
ResultSet rs = null;
try {
String _dbUrl="jdbc:jtds:sqlserver://192.168.0.2:1433;DatabaseName=test;user=test;password=123;";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(_dbUrl);
ps =conn.prepareStatement(sql);
rs =ps.executeQuery();
while(rs.next()){
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
if(rs != null){
rs.close();
}
if(ps != null){
ps.close();
}
if(conn != null){
conn.close();
}
}
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询