?? dbutil.java
字號:
package com.test.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
private static String driver = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://localhost:3306/test";
private static String username = "root";
private static String pasword = "root";
private static Connection conn;
private static Statement stmt;
public static void init() {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
init();
try {
conn = DriverManager.getConnection(url, username, pasword);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static Statement getStatement() {
try {
stmt = getConnection().createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return stmt;
}
public static void close() {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -