• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle JDBC connection in a servlet

 
Lars Ulrich
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your code...
Rene
 
Naveen Sharma
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your error shows that your oracle service is not running
hope the following code helps
Thanks
* 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 (rset.next ()) System.out.println (rset.getString (1));
}
}
 
Lakshmi Kishore
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do u have Oracle client installed in your system?
 
Steffen Foldager
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(dbURL, dbUser, dbPassword);
[ January 16, 2003: Message edited by: Steffen Foldager ]
[ January 16, 2003: Message edited by: Steffen Foldager ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic