Is it necessary to register an access databse with ODBC?
843859Aug 7 2006 — edited Aug 10 2006Hi,
Im just posting to see if anyone has a clue why I can't connect to my databse.
I know there has been thousands of similar posts and believe me, it feels like ive read them all, and none of them seem to hit on the problem im having.
Im creating a website that requires users to login and then access a basic shopping cart. The user details are stored in an access database called "info.mdb".
im currently getting the error:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] DRIVER keyword syntax error
I connect to the databse like so:
package foo;
import java.sql.*;
public class login
{
private String username = "";
private String password = "";
String secure = "no";
public String validate(String username, String password)
{
String DbUser="";
String DbPass="";
Connection con = null;
Statement stat = null;
ResultSet rst = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)DBQ=D:\\web-apps\\info.mdb;");
stat = con.createStatement();
rst = stat.executeQuery( "SELECT * FROM UserDetails;" );
while(rst.next())
{
DbUser=rst.getString("user");
DbPass=rst.getString("pass");
if (username.equals(DbUser) && password.equals(DbPass))
{
secure = "yes";
break;
}
}
return secure;
}
catch(Exception e)
{
e.printStackTrace();
return secure;
}
}
}
I believe the problem to be with the:
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)DBQ=D:\\web-apps\\info.mdb;");
Im at university and cant register the database with the computers. Is there a better way to connect and then access the information?
Any help would be greatly appreciated!