📄 db.java
字号:
package com.csthit.store.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class DB {
public static Connection getConn() throws Exception {
//1 装驱动
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=books", "sa", "");
return conn;
}
public static Statement getStmt(Connection conn) throws Exception {
Statement stmt = conn.createStatement();
return stmt;
}
public static PreparedStatement getPstmt(Connection conn,String sql) throws Exception {
PreparedStatement pstmt = conn.prepareStatement(sql);
return pstmt;
}
public static ResultSet getRS(Statement stmt,String sql) throws Exception {
ResultSet rs = stmt.executeQuery(sql);
return rs;
}
public static void close(Connection conn) throws Exception {
conn.close();
}
public static void close(Statement stmt) throws Exception {
stmt.close();
}
public static void close(ResultSet rs) throws Exception {
rs.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -