Error connecting to database
while trying to import some data from my accessing MS Access 2010 to a mySQL server i receive this error:
Code :
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
below is my code for the connection:
Code :
String user = "root";
String pwd = "pass";
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/newspaper";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "C:/JUN2011.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection conn = DriverManager.getConnection( database ,"","");
Class.forName(driver);
Connection con = DriverManager.getConnection(url, user, pwd);
Statement stmt = con.createStatement();
Statement access=conn.createStatement();
when i run the code in Win XP everything was working perfectly... but once i run it on Win 7.. the error came out..
i am using;
MySQL 5.5 server, MS Access 2010(on Win 7)/MS Access 2003 (Win XP).. my IDE is JCreator Pro 4.5
OS: Window 7 x64bits Ultimate/ Windows XP Pro SP2
Re: Error connecting to database
For MS Access, you need to define a data source. Maybe you defined it on WinXP but not yet on Win7.
Spring 3
Re: Error connecting to database
Quote:
Originally Posted by
cafeteria84
For MS Access, you need to define a data source. Maybe you defined it on WinXP but not yet on Win7.
my XP did not define a source name... also my code specify the access file through the filename variable...
Re: Error connecting to database
Quote:
Originally Posted by
bczm8703
my XP did not define a source name... also my code specify the access file through the filename variable...
Oh, sorry, I have just realized that, so are you sure that the file path is correct? Maybe it is moved around somewhere when you change to Win 7.
Re: Error connecting to database
Quote:
Originally Posted by
cafeteria84
Oh, sorry, I have just realized that, so are you sure that the file path is correct? Maybe it is moved around somewhere when you change to Win 7.
have already checked that and the path is correct...
Re: Error connecting to database
1. Is java 32-bit installed on your machine?
2. You have to create DNS by following,
a). Go to Program Files (x86), System Files,(somewhere, i don't know the exact path) Find for odbcad32.exe and double click
3. Now create DNS and again execute the code.
Re: Error connecting to database
Quote:
Originally Posted by
Mr.777
1. Is java 32-bit installed on your machine?
2. You have to create DNS by following,
a). Go to Program Files (x86), System Files,(somewhere, i don't know the exact path) Find for odbcad32.exe and double click
3. Now create DNS and again execute the code.
do u mean DNS or DSN? as i could not find any DNS in the odbcad32.exe
oh and i sure java is being install as the connecting to mySQL is fine... the error only occur when i try to connect to MS Access...
Re: Error connecting to database
Yeah i mean DSN. And i told you the process, connect by using odbcad32.exe in Syswow64 folder.
Re: Error connecting to database
Quote:
Originally Posted by
Mr.777
Yeah i mean DSN. And i told you the process, connect by using odbcad32.exe in Syswow64 folder.
sorry for asking this... but i still need to specify the DSN??? caouse i m connecting to the access using a path method.. and my XP did not perform this type and it works
Re: Error connecting to database
I will recommend you to read This