sisili
发贴: 6
|
于 2004-09-16 10:30
我把数据库连接bean和运行结果的图也贴出来,请大家给我看看吧
WebDataModule.java如下所示:
import com.borland.dx.dataset.*; import com.borland.dx.sql.dataset.*; import java.sql.*;
public class WebDataModule { public Connection conn; Statement totalStmt; Statement StudentInfoPageStmt; Statement HallMenuPageStmt; ResultSet HallMenuRs; ResultSet StudentInfoRs; public WebDataModule(){ try {jbInit();} catch(Exception e) {e.printStackTrace();} } private void jbInit() throws Exception { String url = "jdbc:odbc:OrderFoodSQLServer"; //创建连接类 Connection conn; //告诉程序使用jdbc与odbc桥创建数据库联接 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //使用DriverManager类的getConnection()方法建立联接, //第一个字符参数定义用户名,第二个字符参数定义密码 conn = DriverManager.getConnection(url, "sa", "sa");
//创建获取全部数据的Statement类 totalStmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); //创建获取分页数据的Statement类,取得StudentInfor数据表的数据 StudentInfoPageStmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); //创建获取分页数据的Statement类,取得HallMenu数据表的数据 HallMenuPageStmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); //设置每页的记录数 StudentInfoPageStmt.setMaxRows; HallMenuPageStmt.setMaxRows; } //取得食堂菜单数据表的数据 public ResultSet getHallMenuRs() { try{ HallMenuRs = totalStmt.executeQuery("select * from HallMenu"); }catch(Exception ex){ex.printStackTrace();} return HallMenuRs; } //分页取得学生信息数据表的数据 public ResultSet getStudentInfoRs(int id) { try{ StudentInfoRs = StudentInfoPageStmt.executeQuery("select * from StudentInfo where id >= " + id); }catch(Exception ex){ex.printStackTrace();} return StudentInfoRs; } //分页取得食堂菜单数据表的数据 public ResultSet getHallMenuRs(int id) { try{ HallMenuRs = StudentInfoPageStmt.executeQuery("select * from HallMenu where id >= " + id); }catch(Exception ex){ex.printStackTrace();} return HallMenuRs; } //关闭数据库联接 public void closeConn(){ try{ conn.close(); }catch(Exception ex){ex.printStackTrace();} } }
(缩略图,点击图片链接看原图)
|