Package com.test.test;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import java.io.IOException;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.util.Properties;
/**
* Link Oracle database via Java JDBC
* @author Administrator
*
*/
public class Oraclejdbctest {
String Driverclass = "Oracle.jdbc.driver.OracleDriver";
Connection con;
public void init (FileInputStream fs) throws ClassNotFoundException,
SQLException, FileNotFoundException, IOException {
Properties Props = new properties ();
Props.load (FS);
String url = props.getproperty ("Db.url");
String userName = Props.getproperty ("Db.user");
String Password = props.getproperty ("Db.password");
Class.forName (Driverclass);
con = drivermanager.getconnection (URL, userName, password);
}
public void Fetch () throws SQLException, IOException {
PreparedStatement PS = con.preparestatement ("Select Sysdate from Dual");
ResultSet rs = Ps.executequery ();
while (Rs.next ()) {
Do the Thing
}
Rs.close ();
Ps.close ();
}
public static void Main (string[] args) throws ClassNotFoundException,
FileNotFoundException, SQLException, IOException {
Oraclejdbctest test = new Oraclejdbctest ();
Configuration file path
FileInputStream fs = null;
Test.init (FS);
Test.fetch ();
}
}
Java JDBC Link Oracle Database