Solved

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

Posted on 2003-12-05
20
34,978 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 250 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
 
LVL 92

Accepted Solution

by:
objects earned 250 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 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

13 Experts available now in Live!

Get 1:1 Help Now