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