fdsa
alert();
package com.nial.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtils {
/** 数据库连接URL */
private String url;
/** 管理员名称 */
private String user = "sa";
/** 管理员密码 */
private String password = "";
/** 临时表名 */
private String m_name = "cc";
/** 建表语句 */
private String m_columnSpec = "ID INTEGER PRIMARY KEY, caller INTEGER,called INTEGER, connected varchar(10) ,beginTime DATE,endTime DATE,inPhyChannel INTEGER, outPhyChannel INTEGER,callType INTEGER,outType INTEGER,timeLength INTEGER";
/** 字段分隔符 */
private String m_separatorSpec = "\\t";
/** 文本数据库链接 */
private Connection connection;
/** 数据文件的位置和名字 */
private String filePathAndName;
DBUtils(String filePathAndName) {
this.setFilePathAndName(filePathAndName);
}
public String getFilePathAndName() {
return filePathAndName;
}
public void setFilePathAndName(String filePathAndName) {
this.filePathAndName = filePathAndName;
}
/**
* 数据库启动
* @throws SQLException
*/
protected void setUp() throws SQLException {
url = "jdbc:hsqldb:file:test;sql.enforce_strict_size=true";
try {
Class.forName("org.hsqldb.jdbcDriver");
} catch (Exception e) {
e.printStackTrace();
System.out.println(this + ".setUp() error: " + e.getMessage());
}
connection = getConnection();
createTable(connection);
}
/**
* 创建一个链接
* @return
* @throws SQLException
*/
private Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, user, password);
}
/**
* 创建一个临时表
* @param connection
* @param filePathAndName
* @throws SQLException
*/
private void createTable(Connection connection) throws SQLException {
String createTable = "DROP TABLE \"" + m_name + "\" IF EXISTS;";
createTable += "CREATE TEXT TABLE \"" + m_name + "\" ( " + m_columnSpec + " );";
connection.createStatement().execute(createTable);
String setTableSource = "SET TABLE \"" + m_name + "\" SOURCE\"" + getDataSourceSpec() + "\"";
connection.createStatement().execute(setTableSource);
}
/**
* 临时表语句
* @param filePathAndName
* @return
*/
private String getDataSourceSpec() {
//忽略第一行数据
return filePathAndName + ";encoding=UTF-8;ignore_first=true;all_quoted=true;cache_scale=12;fs=" + m_separatorSpec;
}
public int getNumTimeLengthByDate(String caller, String startDate, String endDate) throws SQLException {
String selectStmt = "SELECT sum(timeLength) as sumtimelength FROM \"" + m_name + "\" WHERE caller = '"+caller+"' and beginTime between '"+startDate+"' and '"+endDate+"'";
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery(selectStmt);
int time = 0;
while (results.next()) {
time = results.getInt("sumtimelength");
}
return time;
}
public static void main(String[] args) throws SQLException {
DBUtils utils = new DBUtils("D:\\cstpweb-workspace\\hqlTest\\cc.csv");
utils.setUp();
int i = utils.getNumTimeLengthByDate("80703", "2007-12-01 00:00:00", "2007-12-31 00:00:00");
System.out.println(i);
}
}
测试数据
- cc.zip (16.9 KB)
- 描述: 测试数据
- 下载次数: 31
分享到:
相关推荐
使用hsql的文件存储的java代码简单实现,用jdk1.6,maven管理。使用时需要首先在本地建立hsql文件型数据库。
本文档是针对hSQL 数据库方面的基础学习,为了使项目组成员能够达到使用hSQL 数据库的目的。 1.2. 培训对象 开发人员 1.3. 常用词及符号说明 常用词: hsql:一种免费的跨平台的数据库系统 E:\hsqldb:表示是在dos ...
如何使用hsql数据库
hsql数据库,体积最小的数据库,使用最方便的数据库,不用安装,解压就能用,携带方便
Hsqldb-java-连接 在Java编程中使用Hsql(内存数据库)数据库
HSQL数据库下载,纯java数据库,运行速度快,体积小。
提供 数据库jdbc 驱动 下载; 包括: Oracle, sqlserver2000, sqlserver2005 ,mysql ,hsql等主流数据库驱动包
hsql数据库详细教程.pdf
NULL 博文链接:https://taink.iteye.com/blog/707030
收集的全部HSQL DataBase资料(HSQL DataBase-关于Java 的纯数据库)
This package contains the latest release 1 of HSQLDB 1.7.3 HSQLDB is a relational database engine and a set of tools written in Java. ... Documentation and license information can be found in the /doc ...
经典的java小型数据库,可以内存、单机、多机使用,非常棒
HSQL是一个用java语言写的微型数据库,其大小在800k左右。麻雀虽小,但五脏俱全,数据库该有的功能他都有。同样是小型数据库,它要不ACCESS好的多,因为他有JDBC包,而且JDBC包和数据库实体是同一个文件,这就是说...
hsql中文文档 hsql中文文档 hsql中文文档 hsql中文文档 hsql中文文档 hsql中文文档
结合Hibernate数据库无关的特性,非常适合在项目开发的时候使用。 2. 作为单元测试数据库。单元测试的时候,启动HSQLDB的file模式,数据不存盘,可以保证测试原子性。 3. 来回复制,随身携带。 4. 不...
HSQL数据库的安装使用.从下载,到部署系统一系列的操作清晰可见.千万不要跳过步骤.一步一步操作.
此工具可以连接上本地hsql数据库,直接双击tool文件夹下的runManagerSwing就可以了