javams-accessjava-8jdbc-odbc

How to connect Java 8 with MS Access?


I am facing some issue to making a login page in java using ms access database. its not getting username and password from ms access database.

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");
}
}
}

Solution

  • The JDBC-ODBC Bridge is obsolete and has been removed from Java 8, so .getConnection("jdbc:odbc:... is simply not going to work. For an alternative see

    Manipulating an Access database from Java without ODBC