Results 1 to 5 of 5
Thread: oracle JDBC java
- 12-20-2008, 06:05 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 1
- Rep Power
- 0
oracle JDBC java
Hi,
I have a new Vista, my old XP died. I am having difficulty executing a simple JDBC/java progam to access oracle db. When I worked before, I was using
9g. Now it is 10g. I can not figure out if thin client is to be used or OCI. I used both of them before. Where to place the classes12.jar or another one that goes with oci driver. And how to do classpath? Your help will be greatly appreciated. Thanks
My code is as follows:
import java.sql.*; // JDBC package
//import com.inet.tds.JDBCRowSet;
import java.util.*;
// import oracle.jdbc.driver.*;
// import oracle.sql.*;
public class HomeDB
{
/*
run as follows:
C:\Documents and Settings\silia>cd \jj
C:\john>set CLASSPATH=.;c:\oracle9i\classes12;%CLASSPATH%
C:\john>javac HomeDB.java
C:\john>java HomeDB
King: 24000.0
Kochhar: 17000.0
De Haan: 17000.0
Hunold: 9000.0
Ernst: 6000.0
Austin: 4800.0
*/
public static void main(String[] argv)throws SQLException
{
Connection conn=null;
try // may throw a SQLException
{
conn = getConnection();
doQuery (conn);
}
catch (SQLException e)
{
System.err.println(e.getErrorCode() + ": " + e.getMessage());
}
finally // make sure the connection is closed
{
if (conn != null) try {conn.close();} catch (SQLException e) {};
}
//out.close(); // close PrintWriter stream
}
private static Connection getConnection() throws SQLException
{
String username = "scott";
String password = "tiger";
String url = "jdbc:oracle:thin:@localhost:1521:newora";
// "jdbc:oracle:thin:@localhost:1521:COCKYJOB";
Connection conn = null;
String driver = "oracle.jdbc.driver.OracleDriver";
try {
Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
} catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
conn = java.sql.DriverManager.getConnection(url,username, password);
conn.setAutoCommit(false);
return conn;
}
private static void doQuery (Connection c) throws SQLException
{
// statement to be executed
String query = "SELECT ename, job, mgr FROM EMP";
Statement st = null;
ResultSet rs = null;
try // make sure the close statements are executed (in the finally block)
{
// create the statement
st = c.createStatement();
// execute the query
rs = st.executeQuery(query);
// process results
while (rs.next())
{
// get the employee last name
String eName = rs.getString("ename");
String eJob = rs.getString("job");
String eMgr = rs.getString("mgr");
System.out.println("Emp Name:" + eName +
"Job: " + eJob +
"MGR: " + eMgr);
}
}
finally // make sure the close statements are executed
{
// close the result set if it exists
if (rs != null) try {rs.close();} catch (Exception e) {};
// close the statement if it exists
if (st != null) try {st.close();} catch (Exception e) {};
}
}
}
- 12-21-2008, 05:51 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Are you looking that how to add jar files into classpath?
- 02-17-2009, 09:06 AM #3
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
- 05-10-2009, 09:21 AM #4
Member
- Join Date
- Jan 2009
- Posts
- 1
- Rep Power
- 0
hai thanks
- 05-10-2009, 09:37 AM #5
Similar Threads
-
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
By ljustiniano in forum New To JavaReplies: 6Last Post: 02-19-2010, 01:57 PM -
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
By haneeshrawther in forum Advanced JavaReplies: 0Last Post: 03-21-2008, 01:13 PM -
Using JDBC to connect to ORACLE database
By Java Tip in forum Java TipReplies: 0Last Post: 02-10-2008, 11:27 AM -
Jdbc Driver For Oracle
By Swamipsn in forum New To JavaReplies: 0Last Post: 08-14-2007, 04:31 AM -
Oracle and JDBC
By Eric in forum JDBCReplies: 3Last Post: 08-11-2007, 08:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks