IT

[스크랩] jsp mssql2005 연동

네모세모네모 2010. 3. 15. 20:56

 

<%@ page contentType="text/html;charset=euc-kr" language="java" import! = "java.util.*, java.net.*, java.io.*, java.sql.*, common.*"%>

 

<%
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    StringBuffer sql="";
    Common_Data cd = null;
    int rsCount=0;
    
      
    try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        cd = new Common_Data();   
    }catch(ClassNotFoundException ce){
        out.println(ce);
    }
   
    try{             
        conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=DB_NM;user=sa;password=pwd");
        st = conn.createStatement();

        sql.append(" SELECT * FROM TBL_NM ");    

        rs= st.executeQuery(sql.toString());

        while(rs.next()){      
           out.println(rs.getString(1));
        }     
        rs.close();       

    }catch(SQLException se){
        out.println(se);
    }finally{
     try{
        if(rs!=null)rs.close();
        if(st!=null)st.close();
        if(conn!=null)conn.close();
     }catch(SQLException se){}
    }

%>

출처 : 주식&프로그래밍&DB 자료
글쓴이 : shin 원글보기
메모 :