我在使用ms access database在java中创建登录页面时遇到了一些问题。 它没有从ms访问数据库获取用户名和密码。
try
{
String user=t.getText().trim();
String pass=t1.getText().trim();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:balogin");
Statement stat;
stat=con1.createStatement();
ResultSet rs=stat.executeQuery("select * from Table1 where user='"+user+"' and pass='"+pass+"'");
System.out.println("select * from Table1 where user='"+user+"' and pass='"+pass+"'");
int count=0;
while(rs.next())
{
{count=count+1;}
if(count==1)
{
JOptionPane.showMessageDialog(null,"User Found,Access Granted");
ControlPanel cp1=new ControlPanel();
cp1.display();
}
else
{
JOptionPane.showMessageDialog(null,"User not found");
}
}
}
答案 0 :(得分:4)
JDBC-ODBC Bridge已过时,已从Java 8中删除,因此.getConnection("jdbc:odbc:...
根本不起作用。有关替代方案,请参阅