先贴代码:
package org.mingyuan;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.tools.Server;
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Server server = null;
try {
server = Server.createTcpServer(args).start();
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/excel",
"sa", "");
PreparedStatement ps = conn
.prepareStatement("create table excel(`time` double NOT NULL,`location` char(100) default NULL,`data` bigint(20) NOT NULL)");
PreparedStatement ps2 = conn
.prepareStatement("create index idx_time on excel(time)");
PreparedStatement ps3 = conn
.prepareStatement("create index idx_location on excel(location)");
PreparedStatement ps4 = conn
.prepareStatement("create index idx_data on excel(data)");
ps.execute();
ps2.execute();
ps3.execute();
ps4.execute();
PreparedStatement ps5 = conn
.prepareStatement("insert into excel values(0,'c1',1)");
ps5.execute();
PreparedStatement ps6 = conn
.prepareStatement("select * from excel");
ResultSet rs = ps6.executeQuery();
while (rs.next()) {
double time = rs.getDouble(1);
String location = rs.getString(2);
int data = rs.getInt(3);
System.out.println("time:" + time + "-location:" + location
+ "-data:" + data);
}
try {
ps.close();
ps2.close();
ps3.close();
ps4.close();
ps5.close();
ps6.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
server.stop();
}
}
}
h2的数据库文件存放在F:/Users/mingyuan(vista)这是个人目录
package org.mingyuan;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.tools.Server;
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Server server = null;
try {
server = Server.createTcpServer(args).start();
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/excel",
"sa", "");
PreparedStatement ps = conn
.prepareStatement("create table excel(`time` double NOT NULL,`location` char(100) default NULL,`data` bigint(20) NOT NULL)");
PreparedStatement ps2 = conn
.prepareStatement("create index idx_time on excel(time)");
PreparedStatement ps3 = conn
.prepareStatement("create index idx_location on excel(location)");
PreparedStatement ps4 = conn
.prepareStatement("create index idx_data on excel(data)");
ps.execute();
ps2.execute();
ps3.execute();
ps4.execute();
PreparedStatement ps5 = conn
.prepareStatement("insert into excel values(0,'c1',1)");
ps5.execute();
PreparedStatement ps6 = conn
.prepareStatement("select * from excel");
ResultSet rs = ps6.executeQuery();
while (rs.next()) {
double time = rs.getDouble(1);
String location = rs.getString(2);
int data = rs.getInt(3);
System.out.println("time:" + time + "-location:" + location
+ "-data:" + data);
}
try {
ps.close();
ps2.close();
ps3.close();
ps4.close();
ps5.close();
ps6.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
server.stop();
}
}
}
h2的数据库文件存放在F:/Users/mingyuan(vista)这是个人目录