Tuesday, December 1, 2009

Java Oracle Connection

Step1 : First download the classes12.jar file.
Step2:  Add the jar file to java library path
For eclipse –  
goto Projectmenu--->properties--->Click Java Build Path ---> Libraries Tab—> Add External JARs

Example Program for JavaWithOracleConnection
Replace the bold values with your settings.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class TestOracleConnection {
public static void main(String[] args) {
try {
Connection con = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@ipaddressoforacleinstalledmachine:1521:databasename", "username",
"password");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT * from tablename");
while (rs.next()) {
System.out.println("Values------>" + rs.getString("columnname"));
}
s.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 Comments:

Post a Comment

Bookmark and Share
Hihera.com
Increase Page Rank Google
TopBlogDir.blogspot.com button
Best Indian websites ranking
Tips for New Bloggers
TopOfBlogs
The Link Exchange - Your ultimate resource for link exchange!

About This Blog

TopOfBlogs

FEEDJIT Live Traffic Feed

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP