📄 mydata.java
字号:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Vector;
public class MyData {
private Connection conn;
private Statement stmt;
public MyData(){
}
public void init() throws SQLException{
try {
Class.forName("org.hsqldb.jdbcDriver");
conn=DriverManager.getConnection("jdbc:hsqldb:data/data","sa","");
stmt=conn.createStatement();
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public int bytime(int building ,int day ,boolean [] state,Vector Infos) throws SQLException{
int n = 0;
String build,states;
if(building == 0) build = "";
else build = "building = "+building;
states = "";
for(int i = 0; i < 5; i++){
if(state[i])
if(states.isEmpty() && building == 0) states += " w"+ day + (i+1) +" = "+!state[i];
else states += " and w"+ day + (i+1) +" = "+!state[i];
}
if(states.isEmpty()) {
states = "w11 = true and w"+ day + "2 = true and w"+ day + "3 = true and w"+ day + "4 = true and w"+ day + "5 = true";
if(building != 0) states = " and "+states;
}
String sql = "select * from zixishi";
if(!(building == 0&&states.isEmpty())) sql +=" where "+build+states;
//System.out.println(sql);
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
n++;
Vector temp = new Vector();
temp.addElement(rs.getString(2));
String tem = rs.getString(3);
temp.addElement(tem.substring(0, 1));
temp.addElement(tem);
//System.out.println(temp);
Infos.addElement(temp);
}
if(n == 0) {
String text[] ={"null","null","null"};
Infos.addElement(new Vector(Arrays.asList( text )));
}
rs.close();
return n;
}
public void byroom(int build, int room, Vector info) throws SQLException{
String sql = "select * from zixishi where building = "+build+" and room = "+room;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
for(int i=0; i<5; i++){
Vector temp = new Vector();
for(int j=0; j<5; j++){
temp.addElement(booltostr(rs.getBoolean(4+i+5*j)));
}
info.addElement(temp);
}
//System.out.println(temp);
}
}
private String booltostr(boolean b){
if(b) return " V";
else return " X";
}
public String[] room(int build) throws SQLException{
Vector room = new Vector();
String sql = "select room from zixishi where building = "+build;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
room.addElement(rs.getString(1));
}
String [] str = new String[room.size()];
for(int i = 0; i < room.size(); i++){
str[i] = (String)room.elementAt(i);
}
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -