Help classes that connect to Oracle

Source: Internet
Author: User

Package util;

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

Import java.sql.SQLException;


public class Dbconn {

public static Connection getconnection () {
Define a Connection object
Connection Conn=null;
To define a URL resource for a connection database
String url= "JDBC:ORACLE:THIN:@127.0.0.1:1521:ORCL";
Define the user name and password to connect to the database
String username= "System";
String password= "123456";
Load Database Connection Driver
String classname= "Oracle.jdbc.driver.OracleDriver";
try {
Class.forName (ClassName);
} catch (ClassNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Gets the connection object for the database
try {
Conn=drivermanager.getconnection (Url,username,password);
SYSTEM.OUT.PRINTLN ("Database connection established successfully ...");
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Return Connection object
Return conn;
}
public static void Closedb (Connection conn,preparedstatement PS, ResultSet rs) throws sqlexception{
if (conn!=null) {
Conn.close ();
}
if (ps!=null) {
Ps.close ();
}
if (rs!=null) {
Rs.close ();
}
}
}

Help classes that connect to Oracle

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.