在2005年我使用java开发的一套BS系统。对初学者很有帮助。
源代码在线查看: dbconn.java
package com.forcg;
import java.sql.*;
public class DBconn
{String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr="jdbc:odbc:mytable";
Connection conn = null;
ResultSet rs = null;
public DBconn() {
try
{
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try
{
conn = DriverManager.getConnection(ConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}