File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Class.forName() for drive using Oracle 8i Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Class.forName() for drive using Oracle 8i" Watch "Class.forName() for drive using Oracle 8i" New topic
Author

Class.forName() for drive using Oracle 8i

Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Help!!! I'm new to JDBC and am trying to write/read to/from a database on Oracle. It's domain name is:snydb.database and sid:snydb.
Here's a snippet from my code. I keep geting
java.lang.ClassNotFoundException.

I some of this code from this web site, but can't seem to figure out what I'm missing. I'm just about ready to take my Java exam and am looking to pursue JDBC. I understand SQL, but just can't seem to get off the ground floor with this.
Please help!!! I tried using the Oracle web site and had trouble getting a straight answer.
Basically, what url do I use and how can I locate my driver so that I can write the proper class in Class.forName???
Thanks in advance.
[This message has been edited by Thomas Paul (edited April 12, 2001).]
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
it has to be something like this ..
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection dbCon = DriverManager.getConnection("jdbc racle:thin:@address of machine:1521(port where it is listening):servicename", "scott","tiger");
if i use local oracle database then it is like this
Connection dbCon = DriverManager.getConnection("jdbc racle:thin:@localhost:1521:local", "scott","tiger");
hope it will help ;)
Prabhat kumar
[This message has been edited by Thomas Paul (edited April 12, 2001).]
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks prabhat,
I think my problem is that I'm not sure how to find out whether or not the following exist or how to obtain them???
1) @address of machine
2) port
3) servicename
4) "oracle.jdbc.driver.OracleDriver" How can I check for this?
I know these must seem like some really dunb questions, but I am making a career change and am new to it all. I've been reading O'Reilly JDBC and Java and they leave out how to find the above asked questions. Once I establish the connection and drivers, I am good to go!!!
Thanks for your patience.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The address of the machine and the port you should get from your DBA. Make sure that the OraacleDriver is on your classpath. If it is in a jar file, the jar file itself must be on the classpath. If it is exapanded then the directory up to but not including the "oracle" directory must be specified.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
Simple java/jdbc/oracle example program using oracle's thin client. The driver name I have added to my classpath class111.zip.
<code>
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc racle:thin:@127.01.01:1521:SID";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;

try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url,"USERID", "PASSWORD");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage()); }
}
}
</code>
hope this helps ...

------------------
Multi-Platform Database Developer ( on E.S.T. )

[This message has been edited by Monty Ireland (edited April 12, 2001).]


Multi Platform Database Developer & DBA on E.S.T.
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I know this is going to sound really dumb but where did you get the following information from? Please no jokes. ha!
jdbc racle:thin:@S0030947:1521:ispd1
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
Oracle DOC's... very little help!
Misc Web Pages... lots of code fragments...
Spend alot of time searching for one line of code!
jdbcracle:thin:@S0030947:1521:ispd1
jdbc:protocal:subprotocal:@host:port:sid

------------------
Multi-Platform Database Developer ( on E.S.T. )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class.forName() for drive using Oracle 8i