Solved

Trying to talk to a MS Access database with Java

Posted on 2004-04-14
20
290 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
Comment Utility
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
Comment Utility
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
Comment Utility
I'm really new to Java, so how do I "sign the jar"?  
0
 

Author Comment

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

Expert Comment

by:CEHJ
Comment Utility
>>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
Comment Utility
CEHJ, is there another method besides signing the jar?
0
 

Author Comment

by:tminniefield
Comment Utility
I mean signing the applet?
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
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
Comment Utility
Yeah, I don't think that would work :)
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
That's what I thought!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Author Comment

by:tminniefield
Comment Utility
Or something totally different?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 75 total points
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
and in the end I'm going to be connecting to a SQL Database anyway.
0
 

Author Comment

by:tminniefield
Comment Utility
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
Comment Utility
Which browser and Java version?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now