'JAVA MSSQL2005 Connect'에 해당되는 글 1건

  1. 2007.12.17 [JAVA] ms-sql2005 최종본

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();
  }
 }
 
}

Posted by 나비:D
:

BLOG main image
by 나비:D

공지사항

카테고리

분류 전체보기 (278)
Programming? (0)
---------------------------.. (0)
나비의삽질 (5)
Application (177)
SQL (51)
Web (27)
etc. (14)
Omnia (0)
---------------------------.. (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

달력

«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Total :
Today : Yesterday :