我要做个登陆界面,怎样采用jsp java sql 连接数据库查询数据

来源:百度知道 编辑:UC知道 时间:2024/06/19 11:52:12
我用jsp作界面设计 java用来得到jsp传来的用户名,密码数据 并连接数据库。核对用户名,密码 成功返回jsp页面

import java.sql.*; public class DBConnection { public DBConnection() throws ClassNotFoundException { } public static void main(String[] args) throws ClassNotFoundException { try{ //String strurl="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=db.mdb"; String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\SQL\\db.mdb"; //String strurl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=db.mdb";//此为NO-DSN方式 //String strurl="jdbc:odbc:test"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("before connection"); Connection conn=DriverManager.getConnection(strurl); Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery("select * from test"); if(rs.next()) { System.out.println(rs.getString("id")); } }catch(Exception e) { System.out.println(e); } } }