Results 1 to 3 of 3
- 01-03-2012, 07:13 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Connect to Access 2010 DB file (.accdb)
I know there are like a million forum threads about this topic, but so far none of the solutions that I've found have worked! I can connect to an Access DB so easily in VB, but in Java it's a whole lot more difficult :(
Software I'm using
-Windows 7 (64bit)
-Access 2010 (32bit)
- Netbeans 7.0.1 (32bit?)
What I need to do:
-Read/Update/Write/Delete/Perform queries on an Access file (.accdb).
-The project created then needs to be able to run on any computer, without access to a server.
-The user should not have to edit computer settings such as ODBC DSN's to run the project.
Code I've tried:
Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifiedimport java.sql.*;
public class TestA {
public static void main(String[] args)
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "C:\\RPA\\RASP.accdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
}
catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
I also tried to connect to a Derby database from Netbeans as an alternative but that didn't work either:
Error: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriverimport java.sql.*;
public class Derb {
public static void main(String[] args)
{
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDrive r");
// set this to a MS Access DB you have on your machine
//String filename = "C:\\RPA\\MyDbTest";
String database = "jdbc:derby:MyDbTest";
//database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
}
catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
I have tried every combination of "jdbc:odbc:...." and it still doesn't connect. I just need to add/remove/view data from the Access file, and the project needs to be able to access the file on any computer without internet connection AND without the user having to edit computer settings such as ODBC DSN's. I am not too bothered if I have to change to different software to do this, however I would prefer to implement it in Access. I know enough SQL, and SQL*Plus to implement it in an Oracle DB/other.
Is there a (hopefully) super simple way of doing this?
- 01-03-2012, 07:15 PM #2
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Re: Connect to Access 2010 DB file (.accdb)
I was thinking that perhaps I haven't got the correct libraries installed on netbeans.....?
- 01-04-2012, 09:39 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Connect to Access 2010 DB file (.accdb)
I wish people wouldn't do this. VB was written by Microsoft, as was Access, so it's no great surprise that the two of them were built to talk to each other.
OK, have you set up an ODBC datasource for the database? That's what's needed here, which you'll find info on at Microsoft.
If you want to blame someone blame MS for not providing a decent JDBC driver for Access and simply relying on the (frankly rubbish) bridge.
And this is because the Derby JDBC driver is not on your runtime class path.
Have you gone through the JDBC tutorials over at Oracle?
Then don't use Access, because you'll need a data source set up.
Access is rubbish for this when trying to tie it to Java.
Use Derby or a similar embedded db.
Similar Threads
-
Render Japanese Characters & Access Presentation in PowerPoint 2010
By sherazam in forum Java SoftwareReplies: 0Last Post: 08-09-2011, 08:47 AM -
connect java to MS Access Database
By needjavahelp in forum New To JavaReplies: 5Last Post: 07-14-2010, 01:53 PM -
how to connect java to MS Access database
By Manfizy in forum New To JavaReplies: 4Last Post: 12-24-2009, 04:50 PM -
Connect to Access without MS ODBC?
By ribbs2521 in forum New To JavaReplies: 5Last Post: 04-16-2009, 03:33 AM -
connect to microsoft access
By bbq in forum JDBCReplies: 1Last Post: 07-09-2007, 03:33 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks