?? jdbc_util.java
字號:
package com.sunny.address.util;
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.sql.Statement;
import java.util.Properties;
public class JDBC_Util {
private static String driverClass="";
private static String url="";
private static String username="";
private static String password="";
static{
InputStream input =JDBC_Util.class.getResourceAsStream("/jdbc_util.properties");
Properties properties=new Properties();
try{
properties.load(input);
driverClass=properties.getProperty("jdbc.driverClass");
url=properties.getProperty("jdbc.url");
username=properties.getProperty("jdbc.username");
password=properties.getProperty("jdbc.password");
Class.forName(driverClass);
}catch(Exception e){
e.printStackTrace();
}
}
public static Connection getConnection(){
Connection connection=null;
try{
connection=DriverManager.getConnection(url,username,password);
}catch(Exception e){
e.printStackTrace();
}
return connection;
}
private Connection connection=null;
private Statement statement =null;
private ResultSet resultSet =null;
public void addRecord(String insert) throws SQLException{
statement =connection.createStatement();
statement.execute(insert);
statement.close();
}
public void updateRecord(String update) throws SQLException{
statement=connection.createStatement();
statement.execute(update);
statement.close();
}
public ResultSet search(String select) throws SQLException{
statement=connection.createStatement();
statement.execute(select);
return resultSet;
}
public static void close(
ResultSet resultSet,PreparedStatement preparedStatement,Connection connection){
if(resultSet!=null){
try{
resultSet.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(preparedStatement!=null){
try{
preparedStatement.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(connection!=null){
try{
connection.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -