[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sun.jdbc.odbc.jdbcodbcdriver:  How to do CLASSPATH

Posted on 2003-12-05
20
Medium Priority
?
35,338 Views
Last Modified: 2013-11-24
I want to use sun.jdbc.odbc.jdbcodbcdriver and I'm having trouble setting the CLASSPATH.  I have searched high and low for instructions on how to set CLASSPATH, and can't find any.  Would somebody please tell me how to set CLASSPATHs for drivers?  I mean the basics... like where do you go to do it, what commands to run, how do you check to see if you've done it correctly, etc... please help.  Much appreciated.

Also, is there a problem with using this in an applet?  Do I need to use JSP instead?  Thanks from inexperienced Java person here... also a basic beginners book recommendation that is detailed enough to get me into jsp/servlet applications would be highly appreciated as well.
0
Comment
Question by:cxxxcxxx
  • 9
  • 8
  • 2
  • +1
20 Comments
 
LVL 15

Assisted Solution

by:jimmack
jimmack earned 750 total points
ID: 9886016
You may be having trouble simply because it's:

sun.jdbc.odbc.JdbcOdbcDriver

(case sensitive).
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886028
I would highly recommend

Core Servlets and Java Server Pages (2nd edition) by Marty Hall and Larry Brown.

http://www.coreservlets.com and http://www.moreservlets.com
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886035
From your question about applets or JSP (and your interest in JSP/Servlets), I would guess that you should go straight for the JSP route ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 750 total points
ID: 9886076
you don't need to do anything to your classpath to include that driver it is already available.

> Also, is there a problem with using this in an applet?

yes, the default permissions for an applet will not allow its use.
0
 
LVL 92

Expert Comment

by:objects
ID: 9886081
good general tutorial on java available at:
http://java.sun.com/docs/books/tutorial/
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886083
Some information I missed in my previous posts.

You don't need the classpath for this driver since it's available in the JRE (it's in rt.jar).

For other drivers, you just need to include the .jar file that contains them in your classpath.  Usually, you put these jar files in the /lib/ext directories.  JAR files in this directory don't need to be added to the classpath.

If the driver isn't availble to the runtime environment (assuming you're using Class.forName(...)), then this line would throw a ClassNotFoundException.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886085
Hi objects ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 9886113
:-)
0
 

Author Comment

by:cxxxcxxx
ID: 9886181
OK... here's the deal guys.  All I need to do is have a web page collect userid and password, then write userid and password to a database.  Then I need to have another web page for them to log in.... check the same database for valid userid and password, then let them in to yet another web page.  I'm getting the following errors:  unable to resolve symbol connection, and  unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown.

I know this is simple for you guys, but it's important that I have answers to this before I even read the java for dummies book.  I think you're suggesting I use jsp page with a servlet?  If so, what's the best way to go about it?  I'm using netbeans ide 3.5.1.  The thing that makes me frustrated is that when I add a jsp page, I don't get a nice GUI to work with.... if I add a jframe form from the java GUI form section, then I do get the GUI to work with.  So I guess what I really need is a jump start... put me in the right direction and I'll be good to go.  Simple questions, but very important.
0
 

Author Comment

by:cxxxcxxx
ID: 9886188
OK... here's the deal guys.  All I need to do is have a web page collect userid and password, then write userid and password to a database.  Then I need to have another web page for them to log in.... check the same database for valid userid and password, then let them in to yet another web page.  I'm getting the following errors:  unable to resolve symbol connection, and  unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown.

I know this is simple for you guys, but it's important that I have answers to this before I even read the java for dummies book.  I think you're suggesting I use jsp page with a servlet?  If so, what's the best way to go about it?  I'm using netbeans ide 3.5.1.  The thing that makes me frustrated is that when I add a jsp page, I don't get a nice GUI to work with.... if I add a jframe form from the java GUI form section, then I do get the GUI to work with.  So I guess what I really need is a jump start... put me in the right direction and I'll be good to go.  Simple questions, but very important.
0
 
LVL 92

Expert Comment

by:objects
ID: 9886235
if you want to use an applet, then you'll need to either get a different driver, or have your applet call a servlet on the server which will perform the db access.
0
 
LVL 92

Expert Comment

by:objects
ID: 9886265
to get a connection:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con = DriverManager.getConnection(connectstring);

the 1st line is only needed to be called once.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886266
The "must be caught or declared to be thrown" means that you need to put the Class.forName() inside a try ... catch, eg.

try
{
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   .
   .
   .
}
catch (ClassNotFoundException cnfe)
{
   System.err.println(cnfe.toString());
}

Make sure that you do the rest of the database bits (eg. getting a connection etc.) inside the try as well (there's no point doing these things if the driver can't be found).

A JSP page is (basically) just an HTML page with some Java code added between <% and %>.

0
 
LVL 92

Expert Comment

by:objects
ID: 9886269
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886270
Did anybody else get shut-out of EE for the last 1/2 hour (with cyclic links in the questions) or was it just me?
0
 
LVL 92

Expert Comment

by:objects
ID: 9886274
> or was it just me?

no it appears they were tinkering again.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886300
Do you have a servlet container yet (eg. Tomcat)?

If not, you can download it from http://jakarta.apache.org/tomcat/index.html
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9886347
One last thing before I go to bed.  If you go to the coreservlets.com site and scroll down to the bottom of the page, the first edition of Core Servlets and Java Server Pages is available as a free pdf (yes, the whole book ;-)).

If you have a look through that, you'll get a good introduction.

When the EE developers finish tootling with the site ;-), you could try a search for "JdbcOdbcDriver" in the JSP Topic Area.  You might find some JSP code that will give you a good start.
0
 

Expert Comment

by:paragagarwal
ID: 9977096
When you are using the driver :- sun.jdbc.odbc.JdbcOdbcDriver() , it means that you are using Type1 Driver ie making ur java driver is making call to the ODBC provider. There is no need to set the classpath for it. You just have to load the class for this driver thru Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").

Ofcourse ur JDK should be in the path to run ur java application.

Applet Problem:-
You cant use the Type 1 Driver in Applet as applet cant access the File System on the client.
0
 
LVL 92

Expert Comment

by:objects
ID: 10109168
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

830 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