'컴퓨터/JAVA'에 해당되는 글 7건

  1. 2006/07/05 Oracle BLOB
  2. 2006/06/15 The Finalize Method
  3. 2006/06/02 Jrockit
  4. 2006/05/04 Cannot Start a Cloned Connection While in Manual Transaction Mode
  5. 2006/05/04 HOW TO: Get Started with microsoft JDBC

Oracle BLOB

Oracle BLOB 컴퓨터/JAVA 2006/07/05 13:21

Oracle에 접속해서 BLOB 타입의 데이터를 가져와 파일로 저장한다.

package database;

import java.io.*;
import java.sql.*;

import oracle.sql.*;
/**
* Database:Oracle
* IP: 127.0.0.1:1521
* SID: o10g
* USER: scott
* PASS: tiger
* @author hikasiru
*
*/
public class OracleTest {

public static void main(String[] args)
throws SQLException,
ClassNotFoundException,
IOException {
Connection con;
Statement stmt = null;
ResultSet rst  = null;

// 드라이버를 가져옴
Class.forName("oracle.jdbc.driver.OracleDriver");
// DB에 접속을 시도한다.
con = DriverManager.
getConnection("jdbc:oracle:thin:scott/tiger@127.0.0.1:1521:o10g");
con.setAutoCommit( false );
stmt = con.createStatement();

// Table을 삭제하고 생성한다.
//  stmt.executeQuery("DROP TABLE obj_table");
//  stmt.executeQuery("CREATE TABLE obj_table ( " +
//  "no number," +
//  "b blob default empty_blob(), " +
//  "c clob default empty_clob())");

//  삽입
//  rst = stmt.executeQuery("INSERT INTO OBJ_TABLE VALUES (1, empty_blob(), 'clob column data!!!')");
//  rst = stmt.executeQuery("INSERT INTO OBJ_TABLE VALUES (2, empty_blob(), 'clob column data!!!')");
//  rst = stmt.executeQuery("INSERT INTO OBJ_TABLE VALUES (3, empty_blob(), 'clob column data!!!')");
//  rst = stmt.executeQuery("INSERT INTO OBJ_TABLE VALUES (4, empty_blob(), 'clob column data!!!')");

//  검색
rst = stmt.executeQuery("SELECT * FROM OBJ_TABLE");
while ( rst.next()) {
  System.out.print("No: " + rst.getInt(1));
  System.out.print("\tBlob: " + rst.getBlob(2));
  System.out.println("\tClob: " + rst.getClob(3));
}

//  이미지 업로드
//  rst = stmt.executeQuery("SELECT b FROM OBJ_TABLE where no = 2 for update");
//  while (rst.next()) {
//  BLOB blob = (BLOB) rst.getBlob(1);
//  File file = new File("D:\\blue.jpg");
//  long fileLength = (long)file.length();
//  System.out.println("File size: " + fileLength + " bytes");
//  
//  FileInputStream instream = new FileInputStream(file);
//  OutputStream outstream = blob.getBinaryOutputStream();
//  
//  int size = blob.getBufferSize();
//  System.out.println("BufferSize: " + size + " bytes (#)\n");
//  byte[] buffer = new byte[size];
//  int length = -1;
//  int tlength = 0;
//  while ((length = instream.read(buffer)) != -1) {
//  outstream.write(buffer, 0, length);
//  System.out.print("*");
//  tlength += length;
//  }
//  System.out.println("\ntlength: " + tlength);
//  instream.close();
//  outstream.close();
//  
//  System.out.println("\nUpdate done");
//  
//  }

//  이미지 다운로드
rst = stmt.executeQuery("SELECT no, b, c FROM obj_table where no = 1");
while(rst.next()){
  BLOB blob = (BLOB) rst.getBlob(2);
 
  InputStream instream = blob.getBinaryStream();
  String image_name = System.currentTimeMillis() + ".jpg";
  FileOutputStream outstream = new FileOutputStream("D:\\"  
    + image_name);
 
  int size = blob.getBufferSize();
  byte[] buffer = new byte[size];
  int length = -1;  
 
  while((length = instream.read(buffer)) != -1) {
   outstream.write(buffer, 0, length);
  }
 
  outstream.close();
  instream.close();
 
}

System.out.println("\nDownload done");  
rst.close();


//  접속 종료
stmt.close();
con.commit();
con.close();
}
}

Posted by Hikasiru

The Finalize Method

The Finalize Method 컴퓨터/JAVA 2006/06/15 11:08

객체가 서비스로부터 제거 되었을 때 작동할 행동을 정의 하자.
(번역 하니까 이상하군...)

예제.

public class ShutdownDemo {
  public static void main(String[] args) throws Exception {

  // Create an Object with a finalize() method.
  Object f = new Object() {
       public void finalize() {
           System.out.println("Running finalize()");
       }
  };

  // Add a shutdownHook to the JVM
  Runtime.getRuntime().addShutdownHook(new Thread() {
       public void run() {
           System.out.println("Running Shutdown Hook");
       }
  });

  // Unless the user puts -f (for "free") on the command line,
  // call System.exit while holding a reference to
  // Object f, which can therefore not be finalized( ).
  if (args.length == 1 && args[0].equals("-f")) {
       f = null;
       System.gc();
  }

  System.out.println("calling System.exit()");
  System.exit(0);
  }
}


source: Chapter 9, Object Oriented Technique, Java Cookbook 2nd Edtion.

Posted by Hikasiru

Jrockit

Jrockit 컴퓨터/JAVA 2006/06/02 15:26
link: http://commerce.bea.com/index.jsp

Jrockit!?
The first high performance Java Virtual Machine (JVM) optimized to run on Intel platforms.
Posted by Hikasiru

Cannot Start a Cloned Connection While in Manual Transaction Mode

Cannot Start a Cloned Connection While in Manual Transaction Mode 컴퓨터/JAVA 2006/05/04 14:07

link:http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B313181

SYMPTOMS

While using the Microsoft SQL Server 2000 Driver for JDBC, you may experience the following exception:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.


CAUSE

This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver.


Solution
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Cursor;User=User;Password=Password");
con.setAutoCommit(false);

Posted by Hikasiru

HOW TO: Get Started with microsoft JDBC

HOW TO: Get Started with microsoft JDBC 컴퓨터/JAVA 2006/05/04 09:30

link: http://support.microsoft.com/default.aspx?scid=kb;en-us;313100
link: http://support.microsoft.com/default.aspx?scid=kb%3Bko%3B313100


Set your system CLASSPATH variable to include the following entries:

• \Your installation path\Lib\Msbase.jar 
• \Your installation path\Lib\Msutil.jar 
• \Your installation path\Lib\Mssqlserver.jar

To Pass the Connection URL

con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433", "userName", "password");

Ex)
"jdbc:microsoft:sqlserver://127.0.0.1:1433;DataBaseName=TEST;SelectMethod=Direct;User=admin;Password=sa");

Posted by Hikasiru
1 2 
하단 사이드바 열기

BLOG main image