?? dbutil.java
字號(hào):
package com.xial.sqlserver.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
static String driver;
static String url;
static String user;
static String pwd;
static {
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:sqlserver_pubs";
user = "sa";
pwd = "";
}
public static Connection getConnection() throws InstantiationException, IllegalAccessException,
ClassNotFoundException, SQLException {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url, user, pwd);
return conn;
}
public static void close(ResultSet rs, Statement stmt, Connection conn) {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -