dbutils.java
来自「Ajax 一个动态树的源码」· Java 代码 · 共 48 行
JAVA
48 行
package dojo.sample;
import java.io.BufferedReader;
import java.io.IOException;
import java.sql.*;
public class DBUtils {
/*
* Creates the sample data (table and records).
*/
public static void setupDatabase(BufferedReader reader) {
Connection c = null;
Statement stmt = null;
try {
c = openConnection();
stmt = c.createStatement();
// reads the file with the SQL statements
String line;
while ((line = reader.readLine()) != null) {
stmt.execute(line);
}
stmt.close();
c.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
stmt.close();
c.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/*
* Opens a database connection.
*/
public static Connection openConnection() throws SQLException {
Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:dojotree", "sa", "");
return c;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?