Discussion Locked

Connect Oracle using JAVA

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi there,

I am trying to connect to the Oracle Database using JAVA. What are the utilities required and what will be the statements to establish database connectivity and retrive records from Oracle?

Please guide me!

Regards,

Jothiram@hotmail.com

3 replies

by rajiv.srivastava

Hi,
You need to import the javax.sql package in your program and then use the different methods of this class. I am attaching a small code for your reference.
This program assumes that u have a ODBC connectivity to Oracle, it reads the data from table and prints it on console
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:"+yourDSN"+,"scott","tiger");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from anyTableyouwant");
int c =rs.getMetaData().getColumnCount();
while (rs.next())
{
for (int i=1;i<=c ;i++ )
{
System.out.print(rs.getString(i)+"\t");
}
System.out.println();
}

This discussion is closed to new replies.