?? msdb.java
字號:
package cn.ac.cintcm.spider;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class MSDb {
private String fileName;
public MSDb(String fileName) {
this.fileName = fileName;
}
public Connection getConnection() throws ClassNotFoundException, SQLException {
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
StringBuilder url = new StringBuilder("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=");
url.append(System.getProperty("user.dir"));
url.append("\\");
url.append(fileName);
// now we can get the connection from the DriverManager
con = (Connection) DriverManager.getConnection(url.toString() ,"","");
return con;
}
public void createTable(String sql)
{
try
{
Statement stmt = getConnection().createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
catch (SQLException ex)
{
handleSqlException(ex);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void handleSqlException(SQLException ex)
{
System.out.println("\n--- SQLException caught ---\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
System.out.println("");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -