62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
Connection conn = null;
try{
Class.forName(DERBY_DRIVER);
Properties properties = new Properties();
conn = DriverManager.getConnection(DB_URL, properties);
Statement stat = conn.createStatement();
if (j("mac")) //如果表mac存在,就查询字段内容 j是判断表是否存在的工具方法
{
ResultSet result = stat.executeQuery("SELECT * FROM mac where "Memory_Capacity"='4G'");
while (result.next()) {
System.out.println(result.getString(1) + " | " + result.getString(2) + " | " + result.getString(3) +
" | " + result.getString(7) +" | " + result.getString(9) + " | " + result.getString(10));
}
result.close();
stat.close();
conn.close();
}
else
{ //如果表mac不存在,就新建mac表
//.....................................建表语句略
System.out.println("新建表完毕");
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
}
finally {
// 内嵌模式数据库操作用完之后需要关闭数据库,这里没有执行数据库名称则全部关闭.
try {
DriverManager.getConnection("jdbc:derby:;shutdown=true");
} catch (SQLException e) {
e.getMessage();
}
}
}