Hello
I am trying to connect to an access database, i have tried using the
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
but this does not work. I am using Eclipse IDE and running windows 7 64bit. Does anyone know how to make it work?
Thanks
Hello
I am trying to connect to an access database, i have tried using the
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
but this does not work. I am using Eclipse IDE and running windows 7 64bit. Does anyone know how to make it work?
Thanks
Jump to Postyou have to add User Data Source in Win
or
using 3rd. party Driver
Jump to PostOr you can run the code under a 32-bit JVM. The 64-bit JVM will not find the 32-bit Access driver in ODBC, but a 32-bit installation will.
Jump to PostYou could try installing these standalone 64-drivers:
http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16dThey will not install if you have 32-bit MS Office applications installed, which we do here where I work, so I was unable to try …
you have to add User Data Source in Win
or
using 3rd. party Driver
Or you can run the code under a 32-bit JVM. The 64-bit JVM will not find the 32-bit Access driver in ODBC, but a 32-bit installation will.
so do i need to download a new JVM?
You could try installing these standalone 64-drivers:
http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d
They will not install if you have 32-bit MS Office applications installed, which we do here where I work, so I was unable to try them out.
I tried that driver but when i ran my program i get this error:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
Then you got a connection and the driver worked.
Invalid cursor state could be occurring if you tried to read a row value without calling next(). Post the code and the stack trace if you want a more definitive answer.
Here is the code
import java.sql.*;
class Test
{
public static void main(String[] args)
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Cont","","");
Statement s = con.createStatement();
s.executeQuery("SELECT * FROM Customer");
ResultSet rset = s.getResultSet();
while(rset.next());
{
System.out.println(rset.getString("Name") +" " +
rset.getString("Email") + " " +
rset.getInt("Comments"));
}
}
catch (ClassNotFoundException exp) {
System.err.println(exp);
}
catch(SQLException exp)
{
System.err.println(exp);
}
}
}
Try changing your query call to this and see if it makes a difference
ResultSet rset = s.executeQuery("SELECT * FROM Customer");
Still the same error unfortunately.
Replace the println() statements in your catch blocks with exp.printStackTrace() calls so you can see exactly which line is causing the error.
I don't see anything specifically wrong with your code. I suggested the previous change because the Access ODBC driver is picky about re-reading values that have already been read.
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
check and set ResultSet#Type as you really needed, just for my ... then if you are able to call rset.first();
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.