package net.skql.user;
import java.sql.*;
public class ConnectionManager {
private Connection conn = null;
private Statement stmt = null;
private ResultSet rs = null;
//ms-sql jdbc드라이버 로드
static final String msjdbc_driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //구문 주의 2000과 틀리삼 ㅡ.ㅜ
static final String msjdbc_url = "jdbc:sqlserver://127.0.0.1:1433;";
//ms-sql id, password
private static String msid = "sa";
private static String mspassword = "1234";
private static String msdatabase = "testdb";
String url = msjdbc_url;
/**
* Name : ConnectionManager
* Desc : 생성자
*/
public ConnectionManager() {}
public void getDB(dt sqo ) throws Exception{
String sql = "select * from Comm_member";
try{
Class.forName(msjdbc_driver);
}catch(ClassNotFoundException ce){
System.out.println(ce);
}
try{
conn = DriverManager.getConnection(url, msid, mspassword);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString(1));
}
}catch (SQLException se){
System.out.println(se);
} finally {
disconnectDB(); //DB와 연결을 끊는다.
}
}
public void disconnectDB() throws Exception{
try{
conn.close();
stmt.close();
rs.close();
}catch(SQLException se){
System.out.println(se);
}
}
public static void main(String[] args){
ConnectionManager db = new ConnectionManager();
try {
db.getDB();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}