September 7, 2012 at 4:46 PM
The Java classes to connect to Oracle are contained in the Oracle JDBC driver jar file. For recent releases, these are numbered based on the Java version they are compiled for, such as ojdbc14.jar (for Java 1.4), ojdbc15.jar (for Java 1.5), etc. These drivers can be freely downloaded from Oracle's site (free registration is required).
You can tell the Oracle driver which method you want to use to connect to the database (OCI or Thin) through the JDBC connection URL.
Here are some connection URL formats:
Oracle JDBC Thin Driver Formats:
1)Oracle JDBC Thin using a Service Name:
jdbc:oracle:thin:@//<host>:<port>/<service_name>
2)Oracle JDBC Thin using an SID:
jdbc:oracle:thin:@<host>:<port>:<SID>
3)Oracle JDBC Thin using a TNSName:
jdbc:oracle:thin:@<TNSName>
Oracle JDBC OCI Driver Format
jdbc:oracle:oci:@
Follow these steps:
1) Import the following packages in your java file:***
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
2) Load and Register the JDBC driver:***
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
or you can use Class.forName("oracle.jdbc.driver.OracleDriver");
3) Connect to database:***
a) If you are using oracle oci driver,you have to use:
Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:
@oracle.world", "root", "root");
where oracle.world is the TNSNAMES entry and root is the username and password.
b) If you are using oracle thin driver,you have to use:
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:roseindia",
"root", "root");
where localhost is the host,3306 is the port, roseindia is the database and root is the username and password.
4) Querying the database:**
a)create statement:
Statement st = conn.createStatement();
b)write query and execute the query:
ResultSet rs = st.executeQuery("SELECT * from student");
5) Close the statement,resultset and connection:**
rs.close();
st.close();
conn.close();
Try the following code:
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class OracleExample {
public static void main (String[] args) {
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost:3306:Oracle", "rose", "rose");
Statement st = conn.createStatement();
ResultSet rs = sql_stmt.executeQuery("SELECT * from student");
String str = "";
while (rs.next())
{
System.out.println(rset.getInt(1)+" "+ rs.getString(2)+" "+ rset.getFloat(3)+"\n";
}
rs.close();
st.close();
conn.close();
}
catch(Exception e){}
}
}
Related Tutorials/Questions & Answers:
REQ for connection b/w jdbc and oracle database REQ for
connection b/
w jdbc and
oracle database REQ for
connection b/
w jdbc and
oracle database
The Java classes to connect....
b) If you are using
oracle thin driver,you have to use:
Connection conn
what is difference b/w oracle 8i, 9i and 10gwhat is difference
b/
w oracle 8i, 9i and 10g what are the difference between
oracle 8i,9i and 10g?
I am not considering the versions and their supported os, in the interview point of view
Advertisements
how to establish connection b/w java app and mobile phonehow to establish
connection b/
w java app and mobile phone hello,
my name is Dhanraj. i'm doing a project in my college. In that project we need... and also receive response form the server. We are struck with the
connection part
Java Connection to Oracle databaseJava
Connection to
Oracle database HI
I am ubable to connnect
jdbc to
Oracle database.i had gone to control panel >>Administrative tool>>>Data source,in that forDNS name i typed
Oracle and in TNS i culdn't
error oracle database connection?error
oracle database connection? hi now i am trying to connect
oracle database and also insert my data into table, but it's not working.. I created... in
oracle table. my table name is logininfoclient_sla. this is my coding
Could not establish the connection to oracle - JDBC to use:
Connection conn = DriverManager.getConnection("
jdbc:
oracle:oci8... to use:
Connection conn = DriverManager.getConnection ("
jdbc:
oracle:thin... oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("
jdbc:
oracle Oracle Database error - JDBCOracle Database error String query11 = "SELECT product_code...{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("
jdbc:mysql://localhost:3306/register", "root", "root");
Statement
About connection database oracle to javaAbout
connection database oracle to java Hi
I culdn't connect
oracle datebase to java.when i compile the program it is ok.but when i clicked...
Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to javaAbout
connection database oracle to java Hi
I culdn't connect
oracle datebase to java.when i compile the program it is ok.but when i clicked...
Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to javaAbout
connection database oracle to java I culdn't connect
oracle... Panel>>Administrative Tools>>Data Sources in that i selected
Oracle... just typed DNS as
Oracle and for TNS i clicked on the list of TNS. But it has
About connection database oracle to javaAbout
connection database oracle to java I culdn't connect
oracle... Panel>>Administrative Tools>>Data Sources in that i selected
Oracle... just typed DNS as
Oracle and for TNS i clicked on the list of TNS .But it has
About connection database oracle to javaAbout
connection database oracle to java **Hi
I culdn't connect
oracle datebase to java.when i compile the program it is ok.but when i clicked...
Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
difference b/w == and equals()difference
b/
w == and equals() what is the difference between == operator and equals()
Hi Friend,
The == operator checks if the two objects were actually the same object. This operator looks at the actually memory
Database Connection - JDBCDatabase Connection In java How will be connect
Database through
JDBC? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
jdbc/
jdbc-mysql/MysqlConnect.shtml
Thanks
java database connection - JDBCjava
database connection sir i want to join my project with MS access
database. i am making my project in netbeans.please tell me the coding to do... the data into the MS Access
database and retrieve the data from the
database table
difference b/w viewdidload and ViewWillAppear difference
b/
w viewdidload and ViewWillAppear hello all,
what is the difference
b/
w viewdidload and ViewWillAppear ???
hello,ADS_TO_REPLACE_1
when view is loaded then this method run one time
but ViewWillAppear
diff b/w applet and servletdiff
b/
w applet and servlet what is the difference between applet and servlet?
Difference between servlet and applet:
1)An applet is client side programming whereas servlet is server side programming.
2)Applets run
DataBase ConnectionDataBase Connection How to connect java and
Oracle 10g? Tell me
Jdbc connection Underscore b/w consecutive capatalized wordsUnderscore
b/
w consecutive capatalized words I have a text something like this "25km from N of Rio Negro"
I want to add underscore between consecutive Capatalized words having space between them.
Can some one give me
Database connection sql server 2005 - JDBCDatabase connection sql server 2005 Hi all i am developing an application in struts and i need to connect
database for that application using sql server 2005.. can anyone tell me how to make
database connection ..plz help me
Oracle - JDBCOracle fetch variables i wanted to fetch variables from
database using
Oracle Oracle Database connectivity probem ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("
jdbc:
oracle:thin...
Oracle Database connectivity probem hi
Below is the code of
oracle... also set the environment variable like that .;E:\
oracle\ora81\
jdbc\lib
oracle - JDBCoracle sir iam hari
iam doing the project using
oracle
with
jdbc in xp
when iam inserting the data it is giving error like ora-01034:
oracle not available
sir plz.......give me the solution
it is urgent sir
thanku
Hibernate- Oracle connection - Hibernate to make a
connection to
oracle DB from eclipse.
Thanks...Hibernate-
Oracle connection In Eclipse I tried
Windows --> Open perspective--> other
in that
Database Development
Right click
jdbc-oracle - JDBCjdbc-oracle Hi!
sub: image insertion in
oracle:
I inserted the image in
oracle database using java through
jdbc-odbc bridge driver Successfully. But how to view the table contents ? because when I did select*from table
oracle - JDBC to store these two fields into
oracle database
for that i have given one jsp page... it is giving error like
java.sql.SQLException:[MICROSOFT][ODBC Driver for
oracle][
oracle oracle - JDBCoracle HI i am using
ORACLE 10g.
How to i find "TNSNAMES.ORA" file in my system after installation of
ORACLE 10g succussfully.
please send... that depends on the actual network implementation used.
Oracle recommends that SDU
Diff b/w servlet n jsp - Java Interview QuestionsDiff
b/
w servlet n jsp hii
i want to know the difference between servlet and jsp. please give me the details to understand them in correct.
thanks in advance Nothing my friend. Both are same.
Only thing
JDBC Oracle programJDBC Oracle program Here is my code:
import java.sql.*;
public...("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("
jdbc:
oracle:thin:@localhost:8080:
oracle", "System", "System
oracle - JDBCoracle How to collect the backup of tables in
oracle?
plz,, i want some tables in
oracle of one system to be shifted to the another system...;There are two .exe files in
ORACLE, with the FOLLOWING names,generally
Difference b/w jdk 1.1 and 1.2 - Development processDifference
b/
w jdk 1.1 and 1.2 Can you plz specify the changes/developments that have taken place from JDK 1.1 to JDK 1.2 and which version is the industry following currently. Hi friend,
Changes to CLASSPATH
Java vs Oracle Connectivity - JDBC connection with
oracle database? Hi Friend,
Use
Oracle with Java... are using
oracle oci driver,you have to use:
Connection conn = DriverManager.getConnection("
jdbc:
oracle:oci8:
@oracle.world", "root", "root");
where
server database connection - JSP-Servlet ODBC For
Oracle}","scott","tiger");
But how to get the
connection from..." in that case how we will get the
database connection Hi Friend,
which
database you want to use
Oracle or MS Access?
Thanks
Oracle - JDBCOracle How to Use Blob and Clob Data types in
Oracle... Hi friend
BLOB : Binary Large Object
CLOB : Character Large Object
Default storage each time a BLOB or CLOB exceeds 4000 bytes you could cause