• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

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 ]
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic