Solved

Trying to talk to a MS Access database with Java

Posted on 2004-04-14
20
293 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:tminniefield
  • 10
  • 5
  • 4
  • +1
20 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10824748
Your container will have to include the permission mentioned in the error message in its settings
0
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 75 total points
ID: 10824827
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
 

Author Comment

by:tminniefield
ID: 10825416
I'm really new to Java, so how do I "sign the jar"?  
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:tminniefield
ID: 10825535
And CEHJ, are you saying I need to add this to my code - import sun.jdbc.odbc.*;  ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10825597
>>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
 

Author Comment

by:tminniefield
ID: 10825710
CEHJ, is there another method besides signing the jar?
0
 

Author Comment

by:tminniefield
ID: 10825806
I mean signing the applet?
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10825889
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
 

Author Comment

by:tminniefield
ID: 10825921
Yeah, I don't think that would work :)
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10825968
That's what I thought!
0
 

Author Comment

by:tminniefield
ID: 10825983
orangehead911, is signing the applet what you were talking about in your first comment?
0
 

Author Comment

by:tminniefield
ID: 10825988
Or something totally different?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 75 total points
ID: 10826029
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
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10826148
>> 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
 
LVL 92

Expert Comment

by:objects
ID: 10827928
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
 

Author Comment

by:tminniefield
ID: 10832117
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
 

Author Comment

by:tminniefield
ID: 10832621
and in the end I'm going to be connecting to a SQL Database anyway.
0
 

Author Comment

by:tminniefield
ID: 10833221
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
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10835616
Which browser and Java version?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10836361
8-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 50
Java string replace 11 54
Bot application - advice 3 38
hashmap order 17 37
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question