aspose file tools
The moose likes JDBC and the fly likes How to connect to Oracle db using TNS Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How to connect to Oracle db using TNS" Watch "How to connect to Oracle db using TNS" New topic
Author

How to connect to Oracle db using TNS

Steve Campbell
Ranch Hand

Joined: Dec 18, 2000
Posts: 41
I'm able to use the thin client to connect to the db, but can't figure out the syntax for connecting using TNS. Our db group here has put the TNS files onto a common server, and instucted us to us the TNS name only. It works ok using Toad, and when I write C# programs I don't have a problem.
Does anyone know how to connect his way?
Thanks,
Steve
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

have at look at the Oracle9i JDBC Developer's Guide and Reference - Opening a Connection for the JDBC OCI Driver. Specifically it says:
"For the JDBC OCI driver, you can specify the database by a TNSNAMES entry. You can find the available TNSNAMES entries listed in the file tnsnames.ora on the client computer from which you are connecting. On Windows NT, this file is located in the [ORACLE_HOME]\NETWORK\ADMIN directory. On UNIX systems, you can find it in the /var/opt/oracle directory.
For example, if you want to connect to the database on host myhost as user scott with password tiger that has a TNSNAMES entry of MyHostString, enter:
Connection conn = DriverManager.getConnection
("jdbcracleci:@MyHostString", "scott", "tiger");

Note that both the ":" and "@" characters are necessary."
Jamie
[ January 06, 2004: Message edited by: Jamie Robertson ]
Loren Rosen
Ranch Hand

Joined: Feb 12, 2003
Posts: 156
I'm pretty sure (with 8i at least) that you can't use a name server with the thin driver. That driver was designed for use with Applets, where a name server wouldn't make sense.
 
I agree. Here's the link: jrebel
 
subject: How to connect to Oracle db using TNS
 
Similar Threads
what is a TNS name?
Oracle 10g Connection Settings Required
Connect Java With Sql server 2008
Network Adapter Problem
Not able to connect to Oracle DataBase server