cxxxcxxx
asked on
sun.jdbc.odbc.jdbcodbcdriver: How to do CLASSPATH
I want to use sun.jdbc.odbc.jdbcodbcdriv er 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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
Hi objects ;-)
:-)
ASKER
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.ClassNotFoundExc eption; 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.
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.
ASKER
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.ClassNotFoundExc eption; 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.
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.
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.
to get a connection:
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver"). newInstanc e();
Connection con = DriverManager.getConnectio n(connects tring);
the 1st line is only needed to be called once.
Class.forName("sun.jdbc.od
Connection con = DriverManager.getConnectio
the 1st line is only needed to be called once.
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.od bc.JdbcOdb cDriver");
.
.
.
}
catch (ClassNotFoundException cnfe)
{
System.err.println(cnfe.to String());
}
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 %>.
try
{
Class.forName("sun.jdbc.od
.
.
.
}
catch (ClassNotFoundException cnfe)
{
System.err.println(cnfe.to
}
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 %>.
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?
> or was it just me?
no it appears they were tinkering again.
no it appears they were tinkering again.
Do you have a servlet container yet (eg. Tomcat)?
If not, you can download it from http://jakarta.apache.org/tomcat/index.html
If not, you can download it from http://jakarta.apache.org/tomcat/index.html
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.
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.
When you are using the driver :- sun.jdbc.odbc.JdbcOdbcDriv er() , 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.od bc.JdbcOdb cDriver").
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.
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.
Core Servlets and Java Server Pages (2nd edition) by Marty Hall and Larry Brown.
http://www.coreservlets.com and http://www.moreservlets.com