Java Connection Oracle Database detail code

Source: Internet
Author: User

Detailed code:

Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;

public class Dbutil () {

private static final String classname= "Oracle.jdbc.driver.OracleDriver";

private static final String url= "Jdbc:oracle:thin: @localhost: 1521:ORCL";

private static final String username= "Scott"; User name

private static final String password= "Tiger"; Password

Load Driver class

static {

try{

Class.forName (CLASSNAME);

}catch (ClassNotFoundException e) {

E.printstacktrace ();

}

}

Create a connection

public static Connection Getconn () {

Return drivermanager.getconnection (Url,username,password);

}

Close connection

public void Close (Connection con,preparedstatement pst,resultset re) {

if (re!=null) {
try {
Re.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}

if (pst!=null) {
try {
Pst.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}

if (con!=null) {
try {
Con.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}

}

}

The above code for the tool class to write it together to use, only need to call

Java Connection Oracle Database detail code

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.