Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JDBC Connection Help

0 views
Skip to first unread message

Robert Nurse

unread,
May 11, 2001, 10:11:12 AM5/11/01
to
Hi All,

I've just complete a course in Java programming. So forgive me. I'm
trying to write a Java program that can connect to a M$ SQL database
running on another machine. I've set up an ODBC connection
(testODBCConnection) on my workstation that points the database so when
I run the applet in appletviewer it'll connect. I'll worry about
applets on web pages connecting to the DB later. I've verified that
"user" has access to the DB. I'm following the example in my book
(Java: How To Program, by Deitel) which uses similar code to connect:


url = "jdbc:odbc:testODBCConnection";
userName = "user";
password = "123";

try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
jdbcConnection = DriverManager.getConnection(url, userName,
password);
}
catch ( ClassNotFoundException cnfex ) {
System.out.println("Class Not Found Execption:");
cnfex.printStackTrace();
}
catch ( SQLException sqlex ) {
System.out.println("SQL Execption:");
sqlex.printStackTrace();
}
catch ( Exception ex ) {
System.out.println("General Execption:");
ex.printStackTrace();
}


But I'm catching the following "Exception"s:

java.security.AccessControlException: access denied
(java.lang.RuntimePermission
accessClassInPackage.sun.jdbc.odbc)
at
java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at
java.security.AccessController.checkPermission(AccessController.java:
399)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at
java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:150
1)
at
sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:169)

at
sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at ParsdefaultUpdater.init(ParsdefaultUpdater.java:213)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)

What is this exception caused by? Are there any free or inexpensive
JDBC drivers out there? This is just for learning/tinkering purposes.
Thanks.

--
Robert A. Nurse
ICQ Number 207692
http://www.cudbytech.net


dipalikhire

unread,
May 13, 2001, 5:02:46 AM5/13/01
to
hi
this exceptions are not because of jdbc drivers but because of
the applet's security.
since we are developing a untrusted applet java 2 (jdk1.3)
doesn't give permission for us to write/read to a database
through applet.
Actually I am also facing same problem.
but after a long search i don't get any solution.and what
somewhat solutions i got were signing the applet digitaly etc.
But after digitaly signing the applet also you have to buy the
certificates from an authorisation like versign.
that's why now i had switched to Servlets.and now i am doing the
same application which before i was doing using applets, using
servlets.
If you are also developing any application/system my suggession
to you is to do it using servlets/jsp.
if you need more information mail me at
deepal...@usa.net

dipa


jschell

unread,
May 13, 2001, 6:27:43 PM5/13/01
to
I don't believe it is required to provide a digital certificate.

I just you search the java forums using the following search
string.

+applet +jdbc + policy

I read a couple and it seemed to provide several suggestions to
solve this problem.

dipalikhire

unread,
May 14, 2001, 12:46:01 AM5/14/01
to
hi,
i had also searched a lot and after that only i
came to the decision of moving to servlets.
dipa

Robert Nurse

unread,
May 15, 2001, 7:18:29 AM5/15/01
to
You seem to be correct. I converted my applet to run both as an applet
and an application. It connects just fine when run as an application.

dipalikhire wrote:

--


Robert A. Nurse
ICQ Number 207692
http://www.cudbytech.net

------------------------------------------------------------------------------------

Certainly "capable of tracing and comprehending the investigations of
Euclid". Neither dull in imagination, tasteless nor anomalous.
------------------------------------------------------------------------------------

wistar

unread,
May 15, 2001, 9:44:20 AM5/15/01
to
1. Using keytool to generate your own certificate
2. Using jarsigner to sign your applet jar
3. Installing/importing the certificate on the client computer
(verisign and some well known certificates are preinstalled in
browser. )
4. change your java.policy file
5. run appletviewer

for more information, check "Java 2 Network Security"

Robert Nurse

unread,
May 20, 2001, 6:47:30 PM5/20/01
to
I'm drooling now!! Have you done this before? Where is this keytool?

wistar wrote:

--

0 new messages