2011년 5월 18일 수요일

[MSSQL] SQL2005용 JDBC 드라이버 관련

기존버전 : jdbc:microsoft:sqlserver://111.222.111.111:1433;databasename=ABCD 
신규버전 : jdbc:sqlserver://111.222.111.111:1433;databasename=ABCD 

중간에 microsoft 가 빠졌음..주의 


public static void main(String[] args) { 

// Create a variable for the connection string. 
String connectionUrl = "jdbc:sqlserver://111.222.111.111:1433;databasename=ABCD;user=userid;password=pw"; 

// Declare the JDBC objects. 
Connection con = null; 
CallableStatement cstmt = null; 
ResultSet rs = null; 

        try { 
        // Establish the connection. 
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
            con = DriverManager.getConnection(connectionUrl); 
            
            //cstmt = con.prepareCall("{call spBoardDataList(?,?,?,?,?,?)}"); 
           
            cstmt = con.prepareCall("spBoardDataList '0120','','',1,9,0"); 
//             cstmt.setString(1, "0120"); 
//             cstmt.setString(2, ""); 
//             cstmt.setString(3, ""); 
//             cstmt.setInt(4, 1); 
//             cstmt.setInt(5, 9); 
//             cstmt.setInt(6, 0); 
            rs = cstmt.executeQuery(); 

        // Iterate through the data in the result set and display it. 
        while (rs.next()) { 
            System.out.println(rs.getString(1)); 
        } 
        } 
        
// Handle any errors that may have occurred. 
catch (Exception e) { 
e.printStackTrace(); 
} 

finally { 
if (rs != null) try { rs.close(); } catch(Exception e) {} 
    if (cstmt != null) try { cstmt.close(); } catch(Exception e) {} 
    if (con != null) try { con.close(); } catch(Exception e) {} 
} 
}

댓글 없음:

댓글 쓰기