File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Oracle JDBC connection in a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Oracle JDBC connection in a servlet" Watch "Oracle JDBC connection in a servlet" New topic

Oracle JDBC connection in a servlet

Lars Ulrich

Joined: Dec 03, 2002
Posts: 3
I want to connect to an Oracle database using a servlet. How do I connect to the the database. I am getting a "SQLException caught: Io exception: The Network Adapter could not establish the connection" error.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Show us your code...

Regards, Rene Larsen
Dropbox Invite
Naveen Sharma
Ranch Hand

Joined: Mar 23, 2001
Posts: 65
Your error shows that your oracle service is not running
hope the following code helps
* Naveen
class JdbcTest {
public static void main (String args []) throws SQLException {
// Load Oracle driver
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
// Connect to the local database
Connection conn = DriverManager.getConnection ("jdbc racle ci8:@mydatabase", "scott", "tiger");
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select ename from emp");
// Print the name out while ( ()) System.out.println (rset.getString (1));
Lakshmi Kishore
Ranch Hand

Joined: Aug 04, 2001
Posts: 51
Do u have Oracle client installed in your system?

Thanks & Regards<br />glkishore
Steffen Foldager
Ranch Hand

Joined: Mar 22, 2001
Posts: 58
Hi Lars (happy drumming)
My experience with this error when trying to do the same thing is that it means malformed connection string, no service running, service not accesible through firewall. Or it could be something else wich was my case.
You could try to connect using the jdbc thin protocol:
String dbUrl = "jdbcracle:thin:@localhost:1521ors";
// jdbcracle:thin:@host:portatabase
String dbUser = "usr";
String dbPassword = "pwd";
Connection con = DriverManager.getConnection(dbURL, dbUser, dbPassword);
[ January 16, 2003: Message edited by: Steffen Foldager ]
[ January 16, 2003: Message edited by: Steffen Foldager ]

Steffen Foldager<p>Sun Certified Java Programmer<br />Sun Certified Web Component Developer
I agree. Here's the link:
subject: Oracle JDBC connection in a servlet
It's not a secret anymore!