整理中
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();
}
}
}
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();