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 I have a question on connect to oracle 9i Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "I have a question on connect to oracle 9i" Watch "I have a question on connect to oracle 9i" New topic
Author

I have a question on connect to oracle 9i

Davis
Greenhorn

Joined: Oct 02, 2002
Posts: 2
I use nt2000 sp3 and I want to use test.java to connnect the oracle 9i which is installed on solaris 2.7 .
I have search a lot of the docs about this topic ,but i still have some question not been solved . Now states is
I can use the test.java to connect to the other oracle on ntserver ,and the same test.java been copied to solaris ,it can alse connect and query the data on either winnt and solaris oracle database. But ,I can't use my computer(winnt without installing oracle client )to connect to solaris oracle ,why ,I have configurate listern.ora and i make sure it is right. now i will show all the program to you ,give me some opinion please
Tese.java
package test;
import oracle.jdbc.*;
import java.sql.*;
public class Test {
public Test() {
}
public static void main(String[] args) {
Test test1 = new Test();
test1.test();
}
public void test(){
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc racle:thin:@202.199.110.35:1521:test2:"system":"manager");
Statement stmt = conn.createStatement();
/*ResultSet rs = stmt.executeQuery("select * from players");
while(rs.next()){
System.out.println(rs.getString("id"));
System.out.println(rs.getString("name"));
}
*/
ResultSet rs = stmt.executeQuery("select * from player");
while(rs.next()){
System.out.println(rs.getString("id"));
// System.out.println(rs.getString("name"));
}
}
catch(Exception e){
e.printStackTrace();
}
}
}

listener.ora
LISTENER = (ADDRESS_LIST=
(ADDRESS=(PROTOCOL=ipc)(KEY=test2))
(ADDRESS=(PROTOCOL=tcp)(HOST=202.199.110.35)(PORT=1521)) )
sid_list_LISTENER =
(sid_list =
(sid_desc =
(sid_name = PLSExtProc)
(ORACLE_HOME = /export/home/Oracle/oraInventory/OraHome1
PROGRAM=EXTPROC)
))
and i have make class12.zip at the right place ,is anyone give me some reason please?
I am a chinese boy ,not very good at english ,
Thannnnnnnnnnk You!
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1757
    
    3
Davis,
Please adjust your displayed name to meet the JavaRanch Naming Policy. You can do so here.
Also, when posting large blocks of code, it's helpful to enclose them in UBB [ code ] [ /code ] tags.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

What is the SQLException being thrown? Where is it being thrown?
Not sure about your connection code. It should have the form
DriverManager.getConnection("jdbcracle:thin:@202.199.110.35:1521:test2", "system", "manager");
if the above doesn't work, try connecting using the Oracle client ( sql*Plus editor ) to connect using the same connection parameters.
Jamie
[ October 02, 2002: Message edited by: Jamie Robertson ]
John Carnell
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 71
Hi Davis,
First of all your connect string is incorrect. The previous poster has a properly formatted "thin" client connect string.
Oracle has two types of drivers. The thick and the thin driver. The thick driver requires that that you have the Oracle SQL*NET Client installed on your machine and a tnsnames.ora file configured to connect to your database. The connect string is going to use the tnsnames.ora file entry to connect to the database.
The thin driver requires you to pass in a properly formatted string. The thin driver will open a socket and connect directly to the listener without the need for the underlying SQL*NET client.
Oracle has several decent pieces of JDBC examples on their web site and in their documentation. In addition, Wrox has a book called Oracle 9i Java Programming that covers the topic of JDBC in great deal. (As a piece of disclosure: I worked on the SQLJ chapter for that book. I dont get royalties from the book. I think the individual who wrote the JDBC chapters did a fantastic job.)
I hope that helps,
John Carnell


John Carnell<br />Principal Architect<br /> <br />Netchange, LLC<br />1161 HillCrest Heights<br />Green Bay, WI 54313<br /> <br />john.carnell@netchange.us<br /> <br /> <br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/159059228X/ref=jranch-20" target="_blank" rel="nofollow">Pro Jakarta Struts, Second Edition</a>
John Carnell
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 71
Hi Davis,
One other thing. You should re-name your classes12.zip file to classes12.jar. I have run into problems with the Oracle JDBC drivers not being loaded because the class loader for the JVM will only pick a jar file and not a zip file.

Thanks,
John Carnell
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I have a question on connect to oracle 9i