• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with jdbc drivers

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My jdbc program does not create a table with oracle8.
import oracle.jdbc.driver.*;
gives an error " opackage not found".
what are the system requirements .
please hepl.step by step will be easier.as i am new to jdbc
 
Suresh Selvaraj
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here are the steps for connecting to Oracle database.
1.import the standard classes like java.io.*, java.sql.*, java.util.*...
2.Load the oracle driver.
Class.forName("oracle.jdbc.driver.OracleDriver");
3.Establish Connection to the database...
Connection con;
con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:ORCL", "userid", "password");
localhost ==> is your host number.
4.Create statement object...
Statement s = con.createStatement();
5.Construct an sql query:
String query = "select * from EMPTABLE;
6.Execute the query...
ResultSet rs = s.executeQuery(query);
7.Retrieve the values from the ResultSet object...
if (rs != null) {
while(rs.next) {
String s1 = rs.getString(1);
String s2 = rs.getString(2);
.......
.......
}
}
if (con != null) {
try {
con.close();
}
catch(SQLException e1) {}
}
if ( s != null) {
try {
s.close();
}
catch(SQLException e1) {}
}

if ( rs != null) {
try {
rs.close();
}
catch(SQLException e1) {}
}

8.Statements 2 to 7 mentioned above should be in a try-catch-block.
try {
statements 2 thru 7
}
catch(SQLException e) {}
catch(ClassNotFounfException cnfe) {}
9.Ensure the ServerRoot\lib has the following libraries.
The ServerRoot\lib should have Servlet and JSP JAR files.
Also append the oracle.jar in the serverroot\lib classpath.
Hope this is in line with your requirements.
-
Suresh Selvaraj
[This message has been edited by Thomas Paul (edited March 21, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic