'programming > Java' 카테고리의 다른 글
날짜 형태의 string을 date 객체로 바꾸기 (3) | 2006.04.11 |
---|---|
[펌] JDBC Driver load 하는 3가지 방법 (3) | 2006.01.10 |
[펌] Microsoft JDBC 시작하기 (0) | 2004.06.04 |
날짜 형태의 string을 date 객체로 바꾸기 (3) | 2006.04.11 |
---|---|
[펌] JDBC Driver load 하는 3가지 방법 (3) | 2006.01.10 |
[펌] Microsoft JDBC 시작하기 (0) | 2004.06.04 |
서블릿에서 한글 처리 (2) | 2006.03.21 |
---|---|
[펌] Microsoft JDBC 시작하기 (0) | 2004.06.04 |
[펌] JAVA 성능 향상 팁. (0) | 2004.05.28 |
CLASSPATH=.;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar
맨 위로com.microsoft.jdbc.sqlserver.SQLServerDriver
다음 예제 코드에서는 드라이버를 등록하는 방법을 보여 줍니다.Driver d = (Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();맨 위로
jdbc:microsoft:sqlserver://servername:1433
다음 예제 코드에서는 연결 URL을 지정하는 방법을 보여 줍니다.con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433", "userName", "password");서버 이름 값은 IP 주소나 호스트 이름(네트워크가 호스트 이름을 IP 주소로 확인한다고 가정하는 경우)일 수 있습니다. 호스트 이름에 ping 명령을 실행하고 올바른 IP 주소와 함께 응답을 받는지 확인하여 서버 이름 값을 테스트할 수 있습니다.
import java.*;public class Connect{ private java.sql.Connection con = null; private final String url = "jdbc:microsoft:sqlserver://"; private final String serverName= "localhost"; private final String portNumber = "1433"; private final String databaseName= "pubs"; private final String userName = "user"; private final String password = "password"; // Informs the driver to use server a side-cursor, // which permits more than one active statement // on a connection. private final String selectMethod = "cursor"; // Constructor public Connect(){} private String getConnectionUrl(){ return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";"; } private java.sql.Connection getConnection(){ try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password); if(con!=null) System.out.println("Connection Successful!"); }catch(Exception e){ e.printStackTrace(); System.out.println("Error Trace in getConnection() : " + e.getMessage()); } return con; } /* Display the driver properties, database details */ public void displayDbProperties(){ java.sql.DatabaseMetaData dm = null; java.sql.ResultSet rs = null; try{ con= this.getConnection(); if(con!=null){ dm = con.getMetaData(); System.out.println("Driver Information"); System.out.println("\tDriver Name: "+ dm.getDriverName()); System.out.println("\tDriver Version: "+ dm.getDriverVersion ()); System.out.println("\nDatabase Information "); System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName()); System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion()); System.out.println("Avalilable Catalogs "); rs = dm.getCatalogs(); while(rs.next()){ System.out.println("\tcatalog: "+ rs.getString(1)); } rs.close(); rs = null; closeConnection(); }else System.out.println("Error: No active Connection"); }catch(Exception e){ e.printStackTrace(); } dm=null; } private void closeConnection(){ try{ if(con!=null) con.close(); con=null; }catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args) throws Exception { Connect myDbTest = new Connect(); myDbTest.displayDbProperties(); }}이 코드가 성공적으로 실행되면 다음과 비슷하게 출력됩니다.
Connection Successful!Driver Information Driver Name: SQLServer Driver Version: 2.2.0022Database Information Database Name: Microsoft SQL Server Database Version: Microsoft SQL Server 2000 - 8.00.384 (Intel X86) May 23 2001 00:02:52 Copyright (c) 1988-2000 Microsoft Corporation Desktop Engine on Windows NT 5.1 (Build 2600: )Avalilable Catalogs catalog: master catalog: msdb catalog: pubs catalog: tempdb맨 위로
이 오류 메시지는 SQL Server 2000 인증 모드가 Windows 인증 모드로 설정된 경우 나타납니다. JDBC용 Microsoft SQL Server 2000 드라이버는 Windows NT 인증을 사용하여 연결하는 작업을 지원하지 않습니다. SQL Server의 인증 모드를 Windows 인증과 SQL Server 인증을 모두 허용하는 혼합 모드로 설정해야 합니다.
이 오류 메시지는 SQL Server 2000 이전의 SQL Server 버전에 연결하려는 경우 나타납니다. JDBC용 Microsoft SQL Server 2000 드라이버는 SQL Server 2000에서만 연결을 지원합니다.
[펌] JDBC Driver load 하는 3가지 방법 (3) | 2006.01.10 |
---|---|
[펌] JAVA 성능 향상 팁. (0) | 2004.05.28 |
Eclipse 유용한 단축키 모음... (0) | 2004.05.28 |
[펌] JDBC Driver load 하는 3가지 방법 (3) | 2006.01.10 |
---|---|
[펌] Microsoft JDBC 시작하기 (0) | 2004.06.04 |
Eclipse 유용한 단축키 모음... (0) | 2004.05.28 |
한동안 Eclipse를 사용하지 않다가... Java 프로그래밍 할 일이 있어서... 올만에
Eclipse 3.0을 다운 받았다.
Lastest Release로는 3.0이 아직 안 나와서 Stream Stable Builds를 받았다. 정확히 3.0M9이다...
단축키가 많이 바뀐건지 내가 까먹은건지 --''
하나씩 발견할 때마다 정리해보고자 한다.
새삼 Eclipse의 강력한 기능이 부럽다... MS도 이렇게 완벽히 만들면 얼마나 좋을까...
혹시 여기 있는거 말고 아시는 분 덧글 달아주심 ㄳ
[펌] JDBC Driver load 하는 3가지 방법 (3) | 2006.01.10 |
---|---|
[펌] Microsoft JDBC 시작하기 (0) | 2004.06.04 |
[펌] JAVA 성능 향상 팁. (0) | 2004.05.28 |