databaseutilities.java
来自「这是和数据库连接有关的程序.如果有兴趣可以」· Java 代码 · 共 69 行
JAVA
69 行
/*
* 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 + =
减小字号Ctrl + -
显示快捷键?