⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rawdatarecordset.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/location/db/RawDataRecordSet.java,v $// $RCSfile: RawDataRecordSet.java,v $// $Revision: 1.2.2.1 $// $Date: 2004/10/14 18:27:10 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.location.db;import java.sql.*;import java.io.*;import java.util.Hashtable;import java.util.Properties;/** * This class is responsible for retrieving Raw Data from a table in a * Database given a key. Users of this class should provide Database * connection, Table name, Column name that has the key and column * name that has the actual data. * <P> * If you are going to use this, there are a couple of properties to * set: <BR> * prefix.rawDataTableName=table name <BR> * prefix.rawDataColumnName=data column name <BR> * prefix.rawDataKeyColumnName=data key name <BR> *   */public class RawDataRecordSet {    /** Connection object that will be used to retrieve data */    protected Connection connection;    /** Table name from which data would be retrieved */    protected String tableName;    /** Column name in the above table that has Raw Data */    protected String rawDataColumnName;    /** Column name which has the key to lookup above data */    protected String rawDataKeyColumnName;    /**     * A hashtable to keep track of the byte arrays, using the key.     * This will reduce the calls to the database.     */    protected Hashtable byteCache = new Hashtable();    public static final String tableNameProperty = "rawDataTableName";    public static final String rawDataColumnNameProperty = "rawDataColumnName";    public static final String rawDataKeyColumnNameProperty = "rawDataKeyColumnName";    public RawDataRecordSet() {}    public RawDataRecordSet(Connection inConnection) {        setConnection(inConnection);    }    public RawDataRecordSet(Connection inconnection, String prefix,            Properties properties) {        if (prefix != null) {            prefix = prefix + ".";        } else {            prefix = "";        }        setConnection(inconnection);        setTableName(properties.getProperty(prefix + tableNameProperty));        setRawDataColumnName(properties.getProperty(prefix                + rawDataColumnNameProperty));        setRawDataKeyColumnName(properties.getProperty(prefix                + rawDataKeyColumnNameProperty));    }    /** Returns a byte[] array if successfull, null otherwise */    public byte[] getRawData(String lookUpKey) throws SQLException {        byte[] foundit = (byte[]) byteCache.get(lookUpKey.toLowerCase()                .intern());        if (foundit != null) {            return foundit;        }        String query = "Select " + rawDataColumnName + " from " + tableName                + " where " + rawDataKeyColumnName + " = '"                + lookUpKey.toLowerCase() + "' ";        try {            Statement stmt = connection.createStatement();            ResultSet rset = stmt.executeQuery(query);            rset.next();            // This is the only(first hence 1)            InputStream dbis = rset.getBinaryStream(1);            int chunksize = 4096;            byte barr[] = new byte[chunksize];            int imagelength = 0;            ;            try {                imagelength = dbis.read(barr);            } catch (IOException ioE) {                System.err.println("ERROR - while reading raw data\n"                        + ioE.getMessage());            }            //          System.out.println("image length = " + imagelength);            byte image[] = new byte[imagelength];            System.arraycopy(barr, 0, image, 0, imagelength);            // close the resultSet            rset.close();            // Close the statement            stmt.close();            byteCache.put(lookUpKey.toLowerCase().intern(), image);            return image;        } catch (SQLException sqlE) {            //          throw new SQLException(sqlE.getMessage() + "\n"+            //                                 "SQL String " + query);            System.err.println("ERROR - " + sqlE.getMessage() + "\n"                    + "SQL String: " + query);            return null;        }    }    public Connection getConnection() {        return connection;    }    public void setConnection(Connection inConnection) {        connection = inConnection;    }    public String getTableName() {        return tableName;    }    public void setTableName(String inTableName) {        tableName = inTableName;    }    public String getRawDataColumnName() {        return rawDataColumnName;    }    public void setRawDataColumnName(String inrawDataColumnName) {        rawDataColumnName = inrawDataColumnName;    }    public String getRawDataKeyColumnName() {        return rawDataKeyColumnName;    }    public void setRawDataKeyColumnName(String inrawDataKeyColumnName) {        rawDataKeyColumnName = inrawDataKeyColumnName;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -