Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2008, 06:05 AM
Member
 
Join Date: Dec 2008
Posts: 1
Rep Power: 0
silia_motor is on a distinguished road
Default 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 = "jdbcracle:thin:@localhost:1521:newora";
// "jdbcracle: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) {};
}
}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-21-2008, 05:51 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Are you looking that how to add jar files into classpath?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-17-2009, 09:06 AM
Member
 
Join Date: Feb 2009
Location: Delhi
Posts: 62
Rep Power: 0
neeraj.singh is on a distinguished road
Default
Originally Posted by silia_motor View Post
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 = "jdbcracle:thin:@localhost:1521:newora";
// "jdbcracle: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) {};
}
}
}
hi..

use any ide and then add those jars to the project..its very simple
y wasting so many time to set path/classpath???
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-10-2009, 09:21 AM
Member
 
Join Date: Jan 2009
Posts: 2
Rep Power: 0
jaizsankar is on a distinguished road
Smile
hai thanks
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-10-2009, 09:37 AM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,149
Rep Power: 2
CJSLMAN is on a distinguished road
Default
jaizsankar... stop answering nonsense on old posts... you could get yourself banned. If you have a specific Java question/problem, please post it in the correct subforum.

Thank you,
CJSL
__________________
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver ljustiniano New To Java 5 03-03-2009 05:12 PM
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver haneeshrawther Advanced Java 0 03-21-2008 01:13 PM
Using JDBC to connect to ORACLE database Java Tip Java Tips 0 02-10-2008 11:27 AM
Jdbc Driver For Oracle Swamipsn New To Java 0 08-14-2007 04:31 AM
Oracle and JDBC Eric Database 3 08-11-2007 08:49 PM


All times are GMT +2. The time now is 03:07 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org