Trying to talk to a MS Access database with Java

I'm trying to talk to MS Access database using Java, but not having any luck.  I'm still pretty new to java.  The code compiles fine, but throws the following error:

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)


Here's how my code is setup below:
try
{
      String url = "jdbc:odbc://localhost/InternetPanel:8080/InternetPanelDB.mdb";

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      dbconn = DriverManager.getConnection( url, "Admin", "" );

      stmt = dbconn.createStatement();
      rs = stmt.executeQuery( "SELECT SerialNumber FROM tblMainPanelList" );
            }
            catch ( ClassNotFoundException cnfex )
            {
                  // process ClassNotFoundExceptions here
                  cnfex.printStackTrace();
            }
            catch ( SQLException sqlex )
            {
                  // process SQLExceptions here
                  sqlex.printStackTrace();
            }
            catch ( Exception excp )
            {
                  // process remaining Exceptions here
                  excp.printStackTrace();
            }

Any and all help will be greatly appreciated.
tminniefieldAsked:
Who is Participating?
 
Tommy BraasConnect With a Mentor Commented:
If you're running this code inside an applet, you either need to do what CEHJ suggested (which will work for a small number of installations) or sign the jar which contains the classes for your applet.
0
 
CEHJCommented:
Your container will have to include the permission mentioned in the error message in its settings
0
 
tminniefieldAuthor Commented:
I'm really new to Java, so how do I "sign the jar"?  
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tminniefieldAuthor Commented:
And CEHJ, are you saying I need to add this to my code - import sun.jdbc.odbc.*;  ?
0
 
CEHJCommented:
>>And CEHJ, are you saying I need to add this to my code - import sun.jdbc.odbc.*;  ?

Not necessary.

http://www.mindprod.com/jgloss/signedapplets.html (if it's an applet)
0
 
tminniefieldAuthor Commented:
CEHJ, is there another method besides signing the jar?
0
 
tminniefieldAuthor Commented:
I mean signing the applet?
0
 
Tommy BraasCommented:
You can updated the security properties file, but you would have to do that for every single computer that the applet is going to be running on!
0
 
tminniefieldAuthor Commented:
Yeah, I don't think that would work :)
0
 
Tommy BraasCommented:
That's what I thought!
0
 
tminniefieldAuthor Commented:
orangehead911, is signing the applet what you were talking about in your first comment?
0
 
tminniefieldAuthor Commented:
Or something totally different?
0
 
CEHJConnect With a Mentor Commented:
You need to give your code that permission as i mentioned. I thought it was running in a web container, but that fact that it's an applet (at least you haven't gainsaid that it's an applet) doesn't make any difference. It still needs to be given that permission. In the case of an applet, that means signing it
0
 
Tommy BraasCommented:
>> is signing the applet what you were talking about in your first comment?
That's indeed what I talked about in my first comment.
0
 
objectsCommented:
Alternatively use a different database such as mysql.
Or use an application instead of an applet.
Or use a servlet to make your db calls.
0
 
tminniefieldAuthor Commented:
objects, how would I set up the servlet.  I cannot use an application instead of the applet because I have to use ASP.NET.
0
 
tminniefieldAuthor Commented:
and in the end I'm going to be connecting to a SQL Database anyway.
0
 
tminniefieldAuthor Commented:
I've done the signing the Jar file, but now I'm getting another error

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

I think I'm just now specifying the classpath of this driver correctly.  Suggestions.
0
 
Tommy BraasCommented:
Which browser and Java version?
0
 
CEHJCommented:
8-)
0
All Courses

From novice to tech pro — start learning today.