package com.fengjing.webphonebook.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 getConnection() throws Exception{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=address","sa","");
return conn;
}
public static PreparedStatement getPstmt(Connection conn, String sql) throws Exception{
PreparedStatement pstmt = conn.prepareStatement(sql);
return pstmt;
}
public static Statement getStmt(Connection conn) throws Exception{
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
return stmt;
}
public static ResultSet getRs(Statement stmt,String sql) throws Exception{
ResultSet rs = stmt.executeQuery(sql);
return rs;
}
public static void close(Connection conn, Statement stmt, ResultSet rs) throws Exception{
if(rs != null){
rs.close();