JAVA web简单的登录界面jsp实现
packageBean;import
java.sql.*;publicclassDBBean {private
String driverStr = "com.microsoft.sqlserver.jdbc.SQLServerDriver";private
String connStr = "jdbc:sqlserver://localhost:1433; DatabaseName=JXP";private
String dbusername = "sa";private
String dbpassword = "123456";private
Connection conn =null;private
Statement stmt =null;publicDBBean()
{try{
Class.forName(driverStr);
conn
=DriverManager.getConnection(connStr, dbusername, dbpassword);
stmt
=conn.createStatement();
}catch(Exception ex) {
System.out.println(
"数据连接失败!");
}
}publicintexecuteUpdate(String s) {int
result = 0;
System.out.println(
"--更新语句:"+s+"\n");try{
result
=stmt.executeUpdate(s);
}catch(Exception ex) {
System.out.println(
"执行更新错误!");
}returnresult;
}publicResultSet executeQuery(String s) {
ResultSet rs
=null;
System.out.print(
"--查询语句:"+s+"\n");try{
rs
=stmt.executeQuery(s);
}catch(Exception ex) {
System.out.println(
"?执行查询错误!");
}returnrs;
}publicvoidexecQuery(String s){try{
stmt.executeUpdate(s);
}catch(SQLException e) {//TODO Auto-generated catch block
System.out.println("执行插入错误!");
}
}publicvoidclose() {try{
stmt.close();
conn.close();
}catch(Exception e) {
}
}
}
来源: http://www.bubuko.com/infodetail-1958639.html