package com.jwgl.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbUtil {
public static final String DBDRIVER="oracle.jdbc.driver.OracleDriver";
public static final String DBURL="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
public static final String DBUSER="kong";
public static final String DBPASS="kong";
public static Connection conn = null;
public static Statement pstm = null;
public static PreparedStatement pstmt = null;
public static ResultSet rs = null;
public static Connection getConnection(){
try{
Class.forName(DBDRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
}catch(SQLException e){
e.printStackTrace();
}
return conn;
}
public static Statement getStatement(Connection con){
try {
if (con != null) {
pstm = con.createStatement();
}
} catch (SQLException e) {
e.printStackTrace();
}
return pstm;
}
public static PreparedStatement getPreparedStatement(Connection con,String sql) {
if (con != null) {
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
}
return pstmt;
}
public static void close(Connection conn){
if(conn!=null){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
public static void close(Statement stmt){
if(stmt!=null){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
public static void close(PreparedStatement pstmt){
if(pstmt!=null){
try{
pstmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
public static void close(ResultSet rs){
if(rs!=null){
try{
rs.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
public static void main(String[] args) {
System.out.println(DbUtil.getConnection());
}
}