Java JDBC Link Oracle Database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.