| À¥ÇÁ·Î±×·¡¹Ö
[FEED ]
Weblogic + Oracle ·Î °³¹ßµÈ ½Ã½ºÅÛÀ»
Tomcat + sybase ·Î ¹Ù²Ù¸ç "WeblogicÀ¸·Î °³¹ßÇÒ¶§ ¾²´ø DBConnction Class ¼Ò½º " ¸¦ ¹Ù²Û°Í...
±×¶© ¿½ÉÈ÷ oracle·Î¸¸ °³¹ßÇÏ´Ù°¡ Àü ȸ»ç¿¡¼ Åð»ç¸¦ ¸¾¸Ô°í ÀÖÀ»ÂêÀ½.. Sybase·Î ¹Ù²ã¾ß ÇÑ´ÙÇØ¼ ±ÞÁ¶µÈ ¼Ò½º...
import java.sql.*;
import java.io.*;
import java.util.*;
import com.sybase.jdbc2.jdbc.*;
import com.sybase.jdbc2.*;
/**
Sybase DBconnection Class<br>
Developer : wizard <br>
Email : <a href="mailto:wizard@ncafe.net">wizard@ncafe.net</a> <br>
Personal Homepi : <a href="http://wizard.ncafe.net" target="_blank">http://wizard.ncafe.net</a> <br>
Last UpDate : November. 15. 2001. Thursday */
public class DBconn {
private Connection connection;
private Statement statement;
private LogFile log;
public DBconn(){
log = new LogFile();
try {
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
} catch(Exception me) {
log.errLog("Err Class : DBconn.class");
log.errLog("DriverManager Error : "+me.getMessage());
}
try {
connection = DriverManager.getConnection("jdbc:sybase:Tds:10.1.1.1:3800/xbi","id","pwd");
try {
statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
} catch(SQLException e) {
log.errLog("Err Class : DBconn.class");
log.errLog("createStatement Error : "+e.getMessage());
if (connection!=null) {
try {
connection.close();
} catch(SQLException ce) {
log.errLog("Err Class : DBconn.class");
log.errLog("Connection Close Error : "+ce.getMessage());
}
}
}
} catch(SQLException e){
log.errLog("Err Class : DBconn.class");
log.errLog("getConnection Error : "+e.getMessage());
}
}
/** ResultSet À» ±¸ÇÔ */
public ResultSet executeQuery(String sql) throws SQLException{
return statement.executeQuery(sql);
}
/** Update ³ª Delete, Create, Drop µîÀ» À§ÇÑ Methed */
public int executeUpdate(String sql) throws SQLException{
return statement.executeUpdate(sql);
}
/** Ç×»ó clean() À» ÇØÁà¾ß ÇÕ´Ï´Ù. */
public void clean(){
if (statement!=null) {
try {
statement.close();
} catch(SQLException e) {
log.errLog("Err Class : DBconn.class");
log.errLog("statement Close Error : "+e.getMessage());
}
}
if (connection!=null) {
try {
connection.close();
} catch(SQLException e) {
log.errLog("Err Class : DBconn.class");
log.errLog("Connection Close Error : "+e.getMessage());
}
}
}
}
ÅÂ±× : Sybase , DBConn , Java , JSP
| ´ñ±Û(0) | ¿«ÀαÛ(0) | »èÁ¦ | ¼öÁ¤ |
¡Ø Æ®·¢¹é ÁÖ¼Ò : http://wizard.ncafe.net/wt/tb/2310 [ÁÖ¼Òº¹»ç ]
| À¥ÇÁ·Î±×·¡¹Ö
[FEED ]
¾ðÁ¦Â½ ¼Ò½ºÀΰ¡? Çæ....
Weblogic À¸·Î °³¹ßÇÒ¶§ ¾²´ø DBConnection Class ¼Ò½º...
import java.sql.*;
/** DBConnection <br>
Last UpDate :August. 7. 2001. Tuesday.<br>
Developer : Young Sick. Yoon <<a href="mailto:wizard@ncafe.net">wizard@ncafe.net</a>><br>*/
public class DBconn {
private Connection connection;
private Statement statement;
private LogFile log;
public DBconn(){
log = new LogFile();
try {
Class.forName("weblogic.jdbc20.pool.Driver").newInstance();
} catch(Exception me) {
log.errLog("Err Class : DBconn.class");
log.errLog("DriverManager Error : "+me.getMessage());
}
try {
connection = DriverManager.getConnection("jdbc20:weblogic:pool:irisPool");
try {
statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
} catch(SQLException e) {
log.errLog("Err Class : DBconn.class");
log.errLog("createStatement Error : "+e.getMessage());
if (connection!=null) {
try {
connection.close();
} catch(SQLException ce) {
log.errLog("Err Class : DBconn.class");
log.errLog("Connection Close Error : "+ce.getMessage());
}
}
}
} catch(SQLException e){
log.errLog("Err Class : DBconn.class");
log.errLog("getConnection Error : "+e.getMessage());
}
}
/** ResultSet À» ±¸ÇÔ */
public ResultSet executeQuery(String sql) throws SQLException{
return statement.executeQuery(sql);
}
/** Update ³ª Delete, Create, Drop µîÀ» À§ÇÑ Methed */
public int executeUpdate(String sql) throws SQLException{
return statement.executeUpdate(sql);
}
/** Ç×»ó clean() À» ÇØÁà¾ß ÇÕ´Ï´Ù. */
public void clean(){
if (statement!=null) {
try {
statement.close();
} catch(SQLException e) {
log.errLog("Err Class : DBconn.class");
log.errLog("statement Close Error : "+e.getMessage());
}
}
if (connection!=null) {
try {
connection.close();
} catch(SQLException e) {
log.errLog("Err Class : DBconn.class");
log.errLog("Connection Close Error : "+e.getMessage());
}
}
}
}
ÅÂ±× : À¥·ÎÁ÷ , weblogic , Java , JSP , DBConn
| ´ñ±Û(0) | ¿«ÀαÛ(0) | »èÁ¦ | ¼öÁ¤ |
¡Ø Æ®·¢¹é ÁÖ¼Ò : http://wizard.ncafe.net/wt/tb/2307 [ÁÖ¼Òº¹»ç ]
| À¥ÇÁ·Î±×·¡¹Ö
[FEED ]
ÇöÀç º»ÆäÀÌÁö¿¡¼ ¾²À̰í ÀÖ´Â ³ª¸¸ÀÇ DB Connection Class
ÁÖ¼®ÀÌ ¾ø´Ù.. ³ª¸¸ ¾µ·Á°í ¸¸µé¾î ³õÀº°Å¶ó¼...
°ü·ÃµÇ¼ °øºÎÇϰíÀÚ ÇÏ´Â ºÐµéÀÌ ÀÖÀ¸¸é Âü°íÇϽöó...
#DBConn.Class.php
<?
/***************************************************************
ÇÁ·Î±×·¥¸í : DBConn Class
ÀÛ¼ºÀÚ : À±¿µ½Ä (2006-02-17 ¿ÀÈÄ 5:07)
¼³¸í : DataBase Connection Class (Oracle, MySQL)
***************************************************************/
Class DBConn {
const MYSQL = 1 ;
const ORACLE = 2 ;
private $connection ;
private $dbType ;
private $dbHost ;
private $dbPort ;
private $dbSID ;
private $dbName ;
private $dbUser ;
private $dbPassword ;
private $dbCharset ;
function __construct ( $URI ) {
$this -> parseURI ( $URI );
try {
$this -> Connection ();
} catch ( Exception $e ) {
echo $e -> getMessage ();
$this -> __destruct ();
}
}
function __destruct () {
if ( $this -> dbType == MYSQL ) {
@ mysql_close ( $this -> connection );
} else if ( $this -> dbType == ORACLE ) {
@ oci_close ( $this -> connection );
}
}
private function parseURI ( $URI ) {
$URI = str_replace ( "#" , "_sp_" , $URI );
//$mysql_uri = "mysql://localhost:3306/?dbname=meris&username=meris&password=meris&charset=euckr";
//$oracle_uri = "oracle://localhost:1521/?sid=ora10g&username=meris&password=meris&charset=";
$exp = parse_url ( $URI );
if ( strtolower ( $exp [ scheme ])== "mysql" ) {
$this -> dbType = MYSQL ;
} else if ( strtolower ( $exp [ scheme ])== "oracle" ) {
$this -> dbType = ORACLE ;
}
$this -> dbHost = $exp [ host ];
$this -> dbPort = $exp [ port ];
parse_str ( $exp [ query ]);
$this -> dbSID = str_replace ( "_sp_" , "#" , $dbsid );
$this -> dbName = str_replace ( "_sp_" , "#" , $dbname );
$this -> dbUser = str_replace ( "_sp_" , "#" , $username );
$this -> dbPassword = str_replace ( "_sp_" , "#" , $password );
$this -> dbCharset = str_replace ( "_sp_" , "#" , $charset );
}
function freeStatement ( $stmt ) {
if ( $this -> dbType == MYSQL ) {
@ mysql_free_result ( $stmt );
} else if ( $this -> dbType == ORACLE ) {
@ oci_free_statement ( $stmt );
}
}
private function Connection () {
if ( $this -> dbType == MYSQL ) {
if (! $this -> connection =@ mysql_connect ( $this -> dbHost , $this -> dbUser , $this -> dbPassword )) {
throw new Exception ( mysql_error ());
}
if(! mysql_select_db ( $this -> dbName , $this -> connection )){
throw new exception ( mysql_error ());
}
if ( $this -> dbCharset ) {
@ mysql_query ( "set session character_set_connection=" . $this -> dbCharset . ";" );
@ mysql_query ( "set session character_set_results=" . $this -> dbCharset . ";" );
@ mysql_query ( "set session character_set_client=" . $this -> dbCharset . ";" );
}
} else if ( $this -> dbType == ORACLE ) {
if (! $this -> connection = @ oci_connect ( $this -> dbUser , $this -> dbPassword , $this -> dbSID , $this -> dbCharset )) {
$error = oci_error ();
throw new Exception ( $error [ message ]);
}
} else {
throw new Exception ( "No such DB Type" . $this -> dbType );
}
}
function getConnection () {
return $this -> connection ;
}
function destroyConnection () {
if ( $this -> dbType == MYSQL ) {
@ mysql_close ( $this -> connection );
} else if ( $this -> dbType == ORACLE ) {
@ oci_close ( $this -> connection );
}
}
function execute ( $sql , $flag = OCI_COMMIT_ON_SUCCESS ) {
if ( $this -> dbType == MYSQL ) {
if (! $stmt = @ mysql_query ( $sql , $this -> connection )) {
echo mysql_error ();
return false ;
} else {
return $stmt ;
}
} else if ( $this -> dbType == ORACLE ) {
if (! $stmt = @ oci_parse ( $this -> connection , $sql )) {
$error = oci_error ( $this -> connection );
echo $error [ message ];
return false ;
}
if (!@ oci_execute ( $stmt , $flag )) {
$error = oci_error ( $stmt );
echo $error [ message ];
return false ;
} else {
return $stmt ;
}
}
}
function fetchObject (& $obj , $stmt ) {
if ( $this -> dbType == MYSQL ) {
if ( $obj =@ mysql_fetch_object ( $stmt )) {
return true ;
}
} else if ( $this -> dbType == ORACLE ) {
if ( $row = @ oci_fetch_assoc ( $stmt )) {
$rows = Array();
while(list( $key , $val )= each ( $row )) {
$rows [ strtolower ( $key )] = $val ;
}
$obj = (object) $rows ;
return true ;
}
}
return false ;
}
function fetchAssoc (& $obj , $stmt ) {
if ( $this -> dbType == MYSQL ) {
if ( $obj = @ mysql_fetch_assoc ( $stmt )) {
return true ;
}
} else if ( $this -> dbType == ORACLE ) {
if ( $row = @ oci_fetch_assoc ( $stmt )) {
$obj = Array();
while(list( $key , $val )= each ( $row )) {
$obj [ strtolower ( $key )] = $val ;
}
return true ;
}
}
return false ;
}
function fetchRow (& $obj , $stmt ) {
if ( $this -> dbType == MYSQL ) {
if ( $obj = @ mysql_fetch_row ( $stmt )) {
return true ;
}
} else if ( $this -> dbType == ORACLE ) {
if ( $obj = @ oci_fetch_row ( $stmt )) {
return true ;
}
}
return false ;
}
function fetchArray (& $obj , $stmt ) {
if ( $this -> dbType == MYSQL ) {
if ( $obj = @ mysql_fetch_array ( $stmt )) {
return true ;
}
} else if ( $this -> dbType == ORACLE ) {
if ( $row = @ oci_fetch_array ( $stmt )) {
$obj = Array();
while(list( $key , $val )= each ( $row )) {
$obj [ strtolower ( $key )] = $val ;
}
return true ;
}
}
return false ;
}
function commit () {
if ( $this -> dbType == ORACLE ) {
return oci_commit ( $this -> connection );
} else {
return true ;
}
}
function rollback () {
if ( $this -> dbType == ORACLE ) {
return oci_rollback ( $this -> connection );
} else {
return true ;
}
}
function getAffectedRows ( $obj = "" ) {
if ( $this -> dbType == MYSQL ) {
if ( $obj == "" ) {
return mysql_affected_rows ();
} else {
return mysql_affected_rows ( $obj );
}
}
return false ;
}
function getNumRows ( $stmt ) {
if ( $this -> dbType == MYSQL ) {
return mysql_num_rows ( $stmt );
}
return false ;
}
## °è¼Ó Ãß°¡ ¿¹Á¤
}
?>
»ç¿ë¹æ¹ý
Oracle DB »ç¿ë½Ã #oracle.php
<?php
/***************************************************************
ÇÁ·Î±×·¥¸í : Oracle ¿¹Á¦
ÀÛ¼ºÀÚ : À±¿µ½Ä (2006-10-18 ¿ÀÈÄ 5:44)
***************************************************************/
$uri = "oracle://localhost:1521/?sid=ora10g&username=meris&password=meris&charset=" ;
// Class È£Ãâ
$conn = new DBConn ( $uri );
$sql = "SELECT name FROM ttable" ;
// Äõ¸® ½ÇÇà
$stmt = $conn -> execute ( $sql );
// $obj ¿ÀºêÁ§Æ®·Î Fetch
$conn -> fetchObject (& $obj , $stmt );
// $obj->Ä÷³¸í ÇÏ¸é µ¥ÀÌÅÍ ³ª¿È
$name = $obj -> name ;
$obj = null ;
// Statment Free
$conn -> freeStatement ( $stmt );
?>
MySQL DB »ç¿ë½Ã #mysql.php
<?php
/***************************************************************
ÇÁ·Î±×·¥¸í : MySQL ¿¹Á¦
ÀÛ¼ºÀÚ : À±¿µ½Ä (2006-10-18 ¿ÀÈÄ 5:47)
***************************************************************/
$uri = "mysql://localhost:3306/?dbname=meris&username=meris&password=meris&charset=euckr" ;
// Class È£Ãâ
$conn = new DBConn ( $uri );
$sql = "SELECT name FROM ttable" ;
// Äõ¸® ½ÇÇà
$stmt = $conn -> execute ( $sql );
// $obj ¿ÀºêÁ§Æ®·Î Fetch
$conn -> fetchObject (& $obj , $stmt );
// $obj->Ä÷³¸í ÇÏ¸é µ¥ÀÌÅÍ ³ª¿È
$name = $obj -> name ;
$obj = null ;
// Statment Free
$conn -> freeStatement ( $stmt );
?>
´«Ä¡ ºü¸¥ ºÐµéÀº ¹ú½á ´«Ä¡ 쳈°ÚÁö¸¸...
$uri °ª¸¸ ¹Ù±îÁÜÀ¸·Î½á.. MySQL À̵ç Oracle ÀÌµç ¸ðµÎ »ç¿ë°¡´É ÇÏ´Ù.
Sybase ¹× ±âŸ ´Ù¸¥ DBµµ ÇØº¸°í ½ÍÁö¸¸ ¼³Ä¡ µÇ¾î Àִ ȯ°æÀÌ ¾ø¾î¼ Å×½ºÆ® ºÒ°¡.
ÅÂ±× : PHP5 , Class , DBConn , Oracle , MySQL , PHP
| ´ñ±Û(2) | ¿«ÀαÛ(0) | »èÁ¦ | ¼öÁ¤ |
¡Ø Æ®·¢¹é ÁÖ¼Ò : http://wizard.ncafe.net/wt/tb/2296 [ÁÖ¼Òº¹»ç ]
FIRST | PREV | 1 | NEXT | LAST
º» »çÀÌÆ®ÀÇ ³»¿ëÀº Á¤º¸°øÀ¯ ¶óÀ̼¾½º 2.0 : ¿µ¸®±ÝÁö ¸¦ µû¸¨´Ï´Ù. ´Ü, °¢ ÄÁÅÙÃ÷ÀÇ ¶óÀ̼¾½º°¡ ÀÖÀ» °æ¿ì ÇØ´ç ¶óÀ̼¾½º°¡ ¿ì¼±ÇÕ´Ï´Ù. ¶ÇÇÑ ÆÛ°¡½Ç¶§¿¡´Â Ãâó¸¦ ¹àÇôÁֽñ⠹ٶø´Ï´Ù.