整理中

package com.snail.exam.derby;
 
import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
 
import java.util.LinkedList;
import java.util.List;
 
public class DerbyExam {
 
  public static void main(String[] args) throws SQLException {
    String connectionURL = "jdbc:derby:C:\\javadb\\firstdb";
 
    try {
      Connection con = DriverManager.getConnection(connectionURL);
      QueryRunner qr = new QueryRunner();
      ResultSetHandler rsh = new MapListHandler();
      List result = (List) qr.query(con,"SELECT * FROM MAGIC", rsh);
      
      for(Object m:result){
          System.out.println(m);
      }
    } catch (SQLException ex) {
      ex.printStackTrace();
    }
  }
}

BLOB

   QueryRunner qr = new QueryRunner();
   qr.update(con,"DELETE FROM BLOB_TEST");
   qr.update(con,"INSERT INTO BLOB_TEST VALUES(?,EMPTY_BLOB())",new Object[]{1});
   QueryRunner qr = new QueryRunner();
   ResultSetHandler rsh = new MapListHandler();
   List result = (List) qr.query(con, "SELECT * FROM BLOB_TEST", rsh);
   Map record = (Map)result.get(0);
   Blob blob = (Blob)record.get("blob1");
   System.out.println(new String(blob.getBytes(1, (int)blob.length())));
   QueryRunner qr = new QueryRunner();
   ResultSetHandler rsh = new MapListHandler();
   List result = (List) qr.query(con, "SELECT * FROM BLOB_TEST FOR UPDATE", rsh);
   Map record = (Map)result.get(0);
   Blob blob = (Blob)record.get("blob1");
   blob.truncate(0L);
   blob.setBytes(1, sentence);
   QueryRunner qr = new QueryRunner();
   ResultSetHandler rsh = new MapListHandler();
   List result = (List) qr.query(con, "SELECT * FROM BLOB_TEST FOR UPDATE", rsh);
   Map record = (Map)result.get(0);
   Blob blob = (Blob)record.get("blob1");
   blob.truncate(0L);
   OutputStream out = blob.setBinaryStream(0L);
   out.write(sentence);
   out.close();

Java


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2008-07-17 (木) 23:19:17 (5995d)
Short-URL:
ISBN10
ISBN13
9784061426061