Tomcat / server.xml - Oracle Connection pool 설정

Programming/Java 2012.08.12 09:46 Posted by 파란크리스마스

Oracle Connection Pool

		<Resource auth="Container" 
              driverClassName="oracle.jdbc.driver.OracleDriver" 
              factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" 
              maxActive="100" 
              maxIdle="30" 
              maxWait="10000" 
              name="jdbc/testDS" 
              password="tiger" 
              type="javax.sql.DataSource" 
              url="jdbc:oracle:thin:@loclahost:1521:orcl" 
              username="scott"/>

Context 경로 추가

		<Context docBase="C:/workspace/images" path="images" reloadable="true"/>

URIEncoding

		<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>
신고

JDBC 연결

Programming/Java 2012.06.24 10:08 Posted by 파란크리스마스

MySQL JDBC 연결

import java.sql.Connection;
import java.sql.DriverManager;

public class Test {
  public static void main(String[] args) throws Exception {
    Connection conn = null;
    try {
      Class.forName("org.gjt.mm.mysql.Driver"); 
      conn = DriverManager.getConnection("jdbc:mysql://localhost:5515/dbname?user=id&useUnicode=true&characterEncoding=UTF8", "id", "pw");
    } catch (Exception e) {
      e.printStackTrace();
      if (conn!=null) try { conn.close(); } catch (Exception e2) { }
    }
  }
}

Oracle thin

import java.sql.Connection;
import java.sql.DriverManager;

public class Test {
  public static void main(String[] args) throws Exception {
    Connection conn = null;
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver"); 
      conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "scott", "tiger");
      
      System.out.println(conn);
      
    } catch (Exception e) {
      e.printStackTrace();
      if (conn!=null) try { conn.close(); } catch (Exception e2) { }
    }
  }
}

Oracle OCI

import java.sql.Connection;
import java.sql.DriverManager;

public class TestOCI {
  public static void main(String[] args) throws Exception {
    Connection conn = null;
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver"); 
      conn = DriverManager.getConnection("jdbc:oracle:oci:@xe", "scott", "tiger");
      
      System.out.println(conn);
      
    } catch (Exception e) {
      e.printStackTrace();
      if (conn!=null) try { conn.close(); } catch (Exception e2) { }
    }
  }
}
신고

1. 다운로드(mysql-5.5.12-win32.zip)
http://dev.mysql.com/downloads/mysql/5.5.html

2. 압축풀기
압축폴더 : C:\mysql\mysql-5.5.12-win32

3. mysql.ini 파일 작성
경로 : C:\mysql\mysql-5.5.12-win32\mysql.ini
----------------------------------------------------
[mysqld]
port=2233
basedir=C:\mysql\mysql-5.5.12-win32
datadir=C:\mysql\mysql-5.5.12-win32\data
character-set-server=utf8
collation-server=utf8_general_ci

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8
----------------------------------------------------

4. MySQL 서버 NT 서비스에 등록
- 명령 프롬프트 관리자 권한으로 실행

---------------------------------------------------- 
C:\Windows\system32>cd C:\mysql\mysql-5.5.12-win32

C:\mysql\mysql-5.5.12-win32>bin\mysqld.exe --install "MySQL 5.5.12" --defaults-file=C:\mysql\mysql-5.5.12-win32\mysql.ini
Service successfully installed.
----------------------------------------------------



5. 서비스 시작하기

----------------------------------------------------
C:\mysql\mysql-5.5.12-win32>net start "MySQL 5.5.12"
MySQL 5.5.12 서비스를 시작합니다..
MySQL 5.5.12 서비스가 잘 시작되었습니다.
----------------------------------------------------

6. 데이터베이스 접속

----------------------------------------------------
mysql -h localhost -u root -P 2233
----------------------------------------------------

7. 데이터베이스 생성

----------------------------------------------------
mysql> create database db_test;
Query OK, 1 row affected (0.00 sec)
----------------------------------------------------

8. 사용자 추가

----------------------------------------------------
mysql> use mysql;
Database changed
mysql> create user 'test'@'%' identified by 'test00';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'test'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>
----------------------------------------------------

JDBC 접속 테스트

----------------------------------------------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCConnectTest {

 public static void main(String[] args) throws Exception {
  Connection conn = null;
  
  String jdbc_driver = "org.gjt.mm.mysql.Driver";
  String jdbc_url = "jdbc:mysql://192.168.0.62:2233/db_test";
  
  try {
   Class.forName(jdbc_driver);
   conn = DriverManager.getConnection(jdbc_url, "test", "test00");
   System.out.println(conn);   
   conn.close();
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
}
----------------------------------------------------

NT 서비스 지우기
- 명령 프롬프트 관리자 권한으로 실행

----------------------------------------------------
C:\mysql\mysql-5.5.12-win32>bin\mysqld.exe --remove "MySQL 5.5.12"
Service successfully removed.
----------------------------------------------------

신고

PostgreSQL JDBC

Database 2009.08.12 07:34 Posted by 파란크리스마스

출처 : http://www.lug.or.kr/docs/LINUX/KLDP/KoreanDoc/html/JServ_PgSQL-KLDP-html/JServ_PgSQL-KLDP-5.html

1. JDBC 드라이버 받기

http://jdbc.postgresql.org/download.html

2. JDBC Connection 접속 소스

/**
 * JDBC Connection String Examples
 *
 * jdbc:postgresql:database_name
 * jdbc:postgresql://host/database_name
 * jdbc:postgresql://host:port/database_name
 */

import java.sql.*;

public class PgsqlJdbcTest {

  public static void main(String[] args) throws Exception {
   
    String url = "jdbc:postgresql:db_study"; 
    String usr = "scott"; 
    String pwd = "tiger";

    Class.forName("org.postgresql.Driver");
    
    // -- 1

    Connection conn = DriverManager.getConnection(url, usr, pwd);
    System.out.println(conn);
    conn.close();
    
    // -- 2
    url = "jdbc:postgresql://localhost/db_study";
    conn = DriverManager.getConnection(url, usr, pwd);
    System.out.println(conn);
    conn.close();
    
    // -- 3
    url = "jdbc:postgresql://localhost:5432/db_study";
    conn = DriverManager.getConnection(url, usr, pwd);
    System.out.println(conn);
    conn.close();
  }
}

3. 실행 결과

C:\>java -cp .;postgresql-8.4-701.jdbc4.zip PgsqlJdbcTest
org.postgresql.jdbc4.Jdbc4Connection@89fbe3
org.postgresql.jdbc4.Jdbc4Connection@f81843
org.postgresql.jdbc4.Jdbc4Connection@dd5b

신고


 

티스토리 툴바