• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Oracle JDBC connection in a servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us your code...
Rene
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do u have Oracle client installed in your system?
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 = "jdbc:oracle:thin:@localhost:1521:oors";
// jdbc:oracle:thin:@host:port:Database
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 ]
 
please buy my thing and then I'll have more money:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic