//驱动文件
div=com.mysql.jdbc.Driver
utr=jdbc:mysql://localhost:3306/petuse=root
pwd=123
//=====================
package com.java.Jdbc;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class Dbuti {
Connection con=null;
public static String div=null;
public static String utr = null;
public static String use = null;
public static String pwd = null;
static {
Properties pr= new Properties();
String config ="Dbuti.properties";
InputStream is=Dbuti.class.getClassLoader()
.getResourceAsStream(config);
try {
pr.load(is);
div = (String) pr.get("div");
utr =(String)pr.get("utr");
use=(String) pr.get("use");
pwd=(String) pr.get("pwd");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
public Connection getconection(){
try {
Class.forName(div);
con = DriverManager.getConnection(utr, use, pwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public void CloseAll(Connection conn, PreparedStatement pen, ResultSet rs){
try {
if(conn!=null){conn.close();}
if(pen!=null){pen.close();}
if(rs!=null){rs.close();}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}