IT_Programming/Java

[펌] JDBC 별 드라이버 사용법

JJun ™ 2009. 1. 30. 01:25
LONG

//********** 각 경우별 드라이버 연동하기 **************/

** DB2 **
연결 URL : "jdbc:db2:Catalog된 DB명"
드라이버 클래스 : COM.ibm.db2.jdbc.app.DB2Driver

** JDK jdbc-odbc driver (Type1) **
연결 URL : "jdbc:odbc:"
드라이버 클래스 : sun.jdbc.odbc.JdbcOdbcDriver

** Oracle thin driver (Type4) **
연결 URL : "jdbc:oracle:thin:@:port:"
드라이버 클래스 : oracle.jdbc.driver.OracleDriver

** Oracle oci driver (Type2) **
연결 URL : "jdbc:oracle:oci:@"
드라이버 클래스 : oracle.jdbc.driver.OracleDriver

** Sybase jConnect driver (Type2) **
연결 URL : "jdbc:sybase:Tds::"
드라이버 클래스 : com.sybase.jdbc2.jdbc.SybDriver

** Informix JC1 driver (Type4) **
연결 URL : "jdbc:informix-sql://:/:INFORMIXSERVER"
드라이버 클래스 : com.informix.jdbc.IfxDriver

** mSQL Imaginary JDBC driver (Type4) **
연결 URL : "jdbc:msql://:/"
드라이버 클래스 : com.imaginary.sql.msql.MsqlDriver

** Postgres driver (Type4) **
연결 URL : "jdbc:postgresql://:/"
드라이버 클래스 : postgresql.driver

** MM MySQL driver (Type4) **
연결 URL : "jdbc:mysql://:/"
드라이버 클래스 : org.git.mm.mysql.Driver

** Access **

연결 URL : jdbc:odbc:설정한 odbc명

드라이버 클래스 : sun.jdbc.odbc.JdbcOdbcDriver


mysql은 JConnector 3.0 부터는 com.mysql.jdbc.Driver
연결 URL 은 jdbc:mysql://localhost/dbname?Unicode=true&characterEncoding=EUC_KR
같이 인코딩 타입을 직접 줌으로써 한글 변환문제에 좀더 쉽게 해결할 수 있음.



// ******************************Connected To IBM AS/400

Class.forName("com.ibm.as400.access.AS400JDBCDriver");
com = Driver.Manager.getConnection("jdbc:as400://10.20.30.40/testlib;user=user;password=pass");

// ******************************Connected To Unisql

Class.forName("unisql.jdbc.driver.UniSQLDriver");
con = Driver.Manager.getConnection("jdbc:unisql:10.20.30.40:43300:demodb:::", "user","pass");


// ******************************Connected To Jdbc-Odbc Type - 1 Driver

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// con = DriverManager.getConnection("Jdbc:Odbc:dsnname","userid","password");
con = DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};Server=servername;Database=pubs","userid","password");

// ******************************Connected To Ms-Access JDBC ODBC Driver .

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("Jdbc:Odbc:dsnname","","");
// con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=G:/admin.mdb","","");

// ******************************Connected To Ms-Access Type-3 Driver.

Class.forName ("acs.jdbc.Driver");
String url = "jdbc:atinav:servername:5000:C:\\admin.mdb";
String username="Admin";
String password="";
Connection con = DriverManager.getConnection(url,username,password);

// ******************************Connected To Microsoft SQL.

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://servername:1433","userid","password");

// ******************************Connected To Merant.

Class.forName("com.merant.datadirect.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:merant:sqlserver://servername:1433;User=userid;Password=password");

// ******************************Connected To Atinav SqlServer.

Class.forName ("net.avenir.jdbc2.Driver");
con= DriverManager.getConnection("jdbc:AvenirDriver://servername:1433/pubs","userid","password");

// ******************************Connected To J-Turbo.

String server="servername";
String database="pubs";
String user="userid";
String password="password";

Class.forName("com.ashna.jturbo.driver.Driver");
con= DriverManager.getConnection("jdbc:JTurbo://"+server+"/"+database,user,password);

// ******************************Connected To jk Jdbc Driver.

String url= "jdbc:jk:server@pubs:1433";
Properties prop = new Properties();
prop.put("user","userid");
// Set the user name
prop.put("password","password"); // Set the password

Class.forName ("com.jk.jdbc.Driver").newInstance();
con = DriverManager.getConnection (url, prop);

// ******************************Connected To jNetDirect Type - 4 Driver

String sConnect = "jdbc:JSQLConnect://127.0.0.1/database=pubs&user=userid&password=password";
Class.forName ("com.jnetdirect.jsql.JSQLDriver").newInstance();
Connection con= DriverManager.getConnection(sConnect);

// ******************************Connected To AvenirDriver Type - 4 Driver

// String url= "jdbc: AvenirDriver: //servername:1433/pubs";
// java.util.Properties prop = new java.util.Properties ();
// prop.put("user","userid");
// prop.put("password","password");


Class.forName ("net.avenir.jdbc2.Driver");
System.out.println(" Connected To AvenirDriver Type - 4 Driver");
con= DriverManager.getConnection("jdbc:AvenirDriver://servername:1433/pubs","userid","password");

// ******************************Connected To iNet Sprinta2000 Type - 4 Driver

String url="jdbc:inetdae7:servername:1433";
String login="userid";
String password="password";
Class.forName("com.inet.tds.TdsDriver");
System.out.println(" Connected To iNet Sprinta2000 Type - 4 Driver");
con=DriverManager.getConnection(url,login,password);

// ******************************Connected To iNet Opta2000 Type - 4 Driver
String url="jdbc:inetdae7:servername:1433";
String login="sagar";
String password="sagar";
Class.forName("com.inet.tds.TdsDriver").newInstance();
System.out.println(" Connected To iNet Opta2000 Type - 4 Driver");
con=DriverManager.getConnection(url,login,password);

ARTICLE

url 형식의 문자열을 인자로 사용 

[형식]

     jdbc:subprotocol:subname

     subprotocol -> 사용할 드라이버 이름 or 특정 데이터베이스와의 연결을 지정하는 방식

     subname -> 찾고자 하는 특정 데이터베이스명

 

드라이버 로딩

   1. Class.forName 사용

     예-> import java.sql.*;

          ..............

          Class.forName("oracle.jdbc.driver.OracleDriver");

   2. DriverManager.registerDriver 사용

     예-> import java.sql.*;

          .............

          Drivermanager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Class.forName 방법 보다는 DriverManager.registerDriver 방법이 처리 속도가 빠르다.

 

Driver

DB

 

 

Oracle

oracle.jdbc.driver.OracleDriver

 

mssql

com.jk.jdbc.Driver

 

mysql

orj.gjt.mm.mysql.Driver

 

sybase

com.sybase.jdbc2.jdbc.SybDriver

 

db2

COM.ibm.db2.jdbc.app.DB2Driver

 

postgresql

7.0 version : org.postgresql.Driver

6.5 version : postgresql.Driver

 

informix

com.informix.jdbc.IfxDriver

 

odbc brigde

sun.jdbc.odbc.JdbcOdbcDriver

 

 

 

 


Connection시 DB별 URL 구조

DB

 

 

 

Oracle

jdbc:oracle:thin:@hostname:port:SID

String url = "jdbc:oracle:thin:@telecom.kangwon.ac.kr:1521:ORA8";

Class.forName("oracle.jdbc.driver.OracleDriver);

jdbc:oracle:thin

사용할 드라이버

@telecom.kangwon.ac.kr

호스트

1521

port번호(default 1521 사용)

ORA8

oracle DBMS를 구분하기 위한 ID

mssql

jdbc:jk://hostname:port/database=db_name

String url="jdbc:jk://203.237.81.192:1433/database=bosal";

Class.forName("com.jk.jdbc.Driver);

jdbc:jkr

사용할드라이버

// 203,237,81,192 호스트

1433 port번호

database=bosal

사용할 db_name

mysql

jdbc:mysql://db_url:port/db_name

String url = "jdbc:mysql://210.116.114.17:3306/bosal";

Class.forName("orj.gjt.mm.mysql.Driver);

jdbc:mysql사용할 드라이버

// 210.116.114.17호스트 주소

3306

port 번호(default 3306 사용)

bosal 사용할 DB명

sybase

jdbc:sybase:Tds:db_url:port/db_name

String url = "jdbc:sybase:Tds:150.1.203.18:3344/bosal";

Class.forName("com.sybase.jdbc.jdbc.SybDriver);

jdbc:sybase:Tds

사용할 드라이버

150.1.203.18

호스트 주소

3344port 번호

bosaldb 명

db2

jdbc:db2://172.58.654.356:port/db_name

String url = "jdbc:db2://202.228.65.26:9010/PASS";

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver);

jdbc:db2사용할 드라이버

202.228.65.26호스트 주소

9010port 번호

PASS  db 명

postgresql

jdbc:postgresql:db_name

jdbc:postgresql://host/db_name

jdbc:postgresql://host:port/db_name

String url = "jdbc:postgresql://210.116.114.17:5432/bosql";

Class.forName("org.postgresql.Driver); -> version 7.0

Class.forName("postgresql.Driver); -> version 6.5

host

호스트 주소(생략시 default

     localhost(127.0.0.1) 이다.

port

port 번호(default 5432 사용)

database_name

데이타베이스명

informix

jdbc:informix-sqli://hostname:port/db_name

:INFORMIXSERVER=server_name

:user=user_name:password=user_pwd

String url = "jdbc:informix-sqli://localhost:2020/bosal:

INFORMIXSERVER=mydb:user=johyungi:password=jojo";

Class.forName("com.informix.jdbc.IfxDriver);

jdbc:informix-sqli

사용할 드라이버

localhost호스트 주소

2020port 번호

bosaldb 명

INFORMIXSERVER=mydb

DBSERVER 명

user=johyungidb id

password=jojo

해당 db password

odbc brigde

jdbc:odbc:source-name

String url = "jdbc:odbc:bosal";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver);

source-name

 → System DSN에 등록된

     해당 DB의 이름

     드라이버는 썬에서 제공하는

sun.jdbc.odbc.JdbcOdbcDriver  

     사용