?
Solved

java and Oracle

Posted on 2003-03-19
6
Medium Priority
?
361 Views
Last Modified: 2010-03-31
hi friends,i hava  database ib Oracle,i wanto know how i can read data from it in java.
how to establish connection and "bridge".
i know how to read values from MS access database.its very imp,can some one post some
sample code.thanku


riv
0
Comment
Question by:riv9394
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8165958
 Is it the same as MS Access, you jsut need to load a different driver. The rest should be the same.
0
 

Accepted Solution

by:
smilidon earned 320 total points
ID: 8165962
Hi,

if you want to use JDBC, you need the oracle driver. You get it from the oracle web site. download the classes12.zip and put it in your classpath. maybe you must rename it to .jar

you establish the connection with DriverManager.getConnection(
"jdbc:oracle:thin:@url:port:sid", "user", "pw");


I found this example with google(there are many more)

import java.sql.*;

public class DBConnection

{

/** JDBC connection used by the application.
*/
static Connection st_conn;

public static void init(String conn, String usr, String pwd)
{

try {

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
st_conn = DriverManager.getConnection(
"jdbc:oracle:thin:@feast.ucsd.edu:1521:XML", "groupX", "groupXpwd");

} catch (SQLException exc) {

throw new ConversionException( "DB Connection Error.\n" + exc.toString() );
}
}

 

/** Executes SQL updates, inserts, deletes, and DDL statements.
*/
static public boolean write(String U)
{
try {
Statement stmt = st_conn.createStatement();
stmt.executeUpdate(U);
stmt.close();
return true;
} catch (SQLException exc) {
System.out.println("DB Error: " + exc.toString() );
System.out.println("Statement " + U);
return false;
}
}

 

/** Executes SQL query and returns result as JDBC ResultSet object.
*/
static public ResultSet query (String Q)
{

ResultSet rset = null;

try {
Statement stmt = st_conn.createStatement();
rset = stmt.executeQuery(Q);
} catch (SQLException exc) {
System.out.println("DB Error: " + exc.toString() );
System.out.println("Statement " + Q);
return null;
}
return rset;
}
}


Hope this helps...

 

0
 
LVL 35

Expert Comment

by:TimYates
ID: 8166054
> maybe you must rename it to .jar

No need :-)  Just make sure it's in your classpath
0
 

Expert Comment

by:CleanupPing
ID: 9058603
riv9394:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9727203
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept smilidon's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question