Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Oracle JDBC connection in a servlet  RSS feed

 
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.
 
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
 
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));
}
}
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do u have Oracle client installed in your system?
 
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 ]
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!