📄 databaseutilities.java
字号:
/*
* DatabaseUtilities.java
*
* Created on 2007年11月14日, 上午11:44
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package jdbcjframe;
/**
*
* @author user
*/
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;
import sun.jdbc.odbc.JdbcOdbcDriver;
public class DatabaseUtilities {
/** Creates a new instance of DatabaseUtilities */
static String jdbcDriver="sun.jdbc.odbc.JdbcOdbcDriver";
static String dbName="Contacts";
static String urlRoot="jdbc:odbc:Test";
private ActionListener exceptionListener=null;
public DatabaseUtilities() {
registerDriver();
}
private void registerDriver() {
try{
Class.forName(jdbcDriver);
DriverManager.registerDriver(new JdbcOdbcDriver());
}catch(ClassNotFoundException e){
reportException(e.getMessage());
}catch(SQLException e){
reportException(e.getMessage());
}
}
public void execute(String SQLCommand){
String url=urlRoot+dbName;
try{
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
stmt.execute(SQLCommand);
con.close();
}catch(SQLException e){
reportException(e.getMessage());
}
}
public void setExceptionListener(ActionListener exceptionListener){
this.exceptionListener=exceptionListener;
}
private void reportException(String exception) {
if(exceptionListener!=null){
ActionEvent evt=new ActionEvent(this,0,exception);
exceptionListener.actionPerformed(evt);
}
else{
System.err.println(exception);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -