Click to See Complete Forum and Search --> : Applet - Servlet - MS_Access


einhugur
April 9th, 1999, 03:32 PM
Hello

I'm having really big problem with connecting to MS Access database
from Java Servlets

The following code will Work on:
J++ - As Applet = OK
Metrowerks CodeWarrior Java Applet = Hard crash, no exception
Sun Java Web server = Hard crash, no exception

The crash occurs on the second line, con = ....
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con = DriverManager.getConnection(new String("jdbc:odbc:Northwind"), "", "" );
}
catch (Exception e)
{
}

If anyone knows what to do, has any experience in connection Java Applets and or Servlets to MS Access database or knows of good working samples. Then please let me know.

Also if anyone knows of native MS Access drivers for JDBC, then please let me know.

Thanks in advance

April 15th, 1999, 11:46 AM
You aren't creating an instance of the JdbcOdbcDriver. You need your code to look like this:

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

con = DriverManager.getConnection(new String("jdbc:odbc:Northwind"), "", "" );
}
catch (Exception e)
{
}


That should do it.

Matty

Phil Jacobs
May 19th, 1999, 08:52 PM
Go here http://recanati.ensmp.fr:81/jdk/guide/jdbc/SimpleSelect.doc.html and look at how it was done.

Sameet Nasnodkar
May 24th, 1999, 09:44 AM
Hi

What I can figure from your piece of code is that your MS-Access database has no user and password. This means that you need not give one.

Secondly, your connection string should be "jdbc:odbc:Northwind" where Northwind is the Data Source Name ( Commonly known in ODBC as DSN ) and not the database name.

so finally your statement 2 will be as follows:

con = DriverManager.getConnection("jdbc:odbc:Northwind");

try this and reply ....... have fun !!!!!!!

Sameet Nasnodkar
Senior Executive - Web Development
AFL Limited

amaresh
May 26th, 1999, 11:27 AM
Using MS-Access with Jdbc-Odbc bridge certainly works fine. (though using the bridge is not recommended much).
In your question, I need some more information. What exception are you getting? Both the lines you have mentioned in your code can throw exceptions. Let me know if you are getting SQL exception or ClassNotFound......
I will be able to suggest more depending on your exception type..
Thanks,
Amaresh

amaresh
May 26th, 1999, 11:39 AM
No need to have "newInstance()" on the first line of your code. Class.forName() will do. Look at Smeeth's solution. I think that's correct.

amaresh
May 26th, 1999, 11:40 AM
There are so many things that can go wrong:
1) Is the DSN registered. (Need to do it through Control Panel)
2) Are you calling this way: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
3) Though you may not have user and password for your db, still I suggest you call in the following way:
Connection cn = DriverManager.getConnection("jdbc:odbc:xxxdb", "", "");
Try these and let me know. Also, let me know the exception..
--Amaresh

einhugur
May 26th, 1999, 11:50 AM
Hello, and thank you all for your Replies

It turned out that the solution is that in order to run JavaWebServer with JDBC-ODBC brigde then the JRE needed to be shut down. Which Sun had some backdoor solution to do so by runnning the server in console.

After this then the Servlet ran without a glitch : )