java连数据库课程设计报告_数据库课程设计报告-教学管理系统(+java实现)

主界面如下所示:

9

〈5〉关键代码如下:由于代码太多,以下只写出很少的一部分代码 1》对数据库的操作:

public class ConneJdbc {

protected static Connection connection = null; private Connection con = null; private ResultSet rs = null;

private ResultSetMetaData rsmd = null; public ConneJdbc() { try { Class.forName(\ connection = DriverManager.getConnection( \ \

} catch (java.lang.ClassNotFoundException classnotfound) { classnotfound.printStackTrace(); } catch (java.sql.SQLException sql) { sql.printStackTrace(); } }

public Connection getCon() { return connection; }

10

public Vector selectSql(String sql) { Vector vdata = new Vector(); try { rs = connection.prepareStatement(sql).executeQuery(); rsmd = rs.getMetaData(); while (rs.next()) vdata.addElement(rs.getObject(1)); } catch (SQLException e) { e.printStackTrace(); }

return vdata; }

public String selectOne(String sql) { ResultSet rs = null;

ResultSetMetaData rsmd = null; try { rs = connection.prepareStatement(sql).executeQuery(); rsmd = rs.getMetaData(); if (rs.next()) return (String)rs.getObject(1); } catch (SQLException e) { e.printStackTrace(); }

return null; }

public boolean inTable(String user, String pa) throws SQLException { Statement stmt = null;

PreparedStatement pstmt = null; ResultSet rs = null;

String sql = \ \ + pa + \

rs = connection.prepareStatement(sql).executeQuery(); if(rs.next())return true; else return false; } }

2》表格模型的处理:

public class SqlTableModel extends DefaultTableModel { private Connection con = null; private ResultSet rs = null;

private ResultSetMetaData rsmd = null;

public SqlTableModel(String sqlStr, String[] name) { con = new ConneJdbc().getCon();

11

try{

rs = con.prepareStatement(sqlStr).executeQuery(); rsmd = rs.getMetaData();

for(int i=0; iwhile(rs.next()){

Vector vdata = new Vector();

for ( int i = 1 ; i <= rsmd.getColumnCount() ; i ++){ vdata.addElement(rs.getObject(i)); }

addRow(vdata); }

}catch(java.sql.SQLException sql){ sql.printStackTrace(); }finally { try { con.close(); } catch (SQLException e) { e.printStackTrace(); }

} }

3)Updatabase的一部分代码:

public class UpdateDatebase extends ConneJdbc { private Statement stmt = null;

private PreparedStatement pstmt = null; private String infoStr = null; private String sql;

public UpdateDatebase() { }

public boolean insert(DepData data) throws SQLException {

String sql = \into department (depth_name,discription) values ('\

+ data.getDepth_name() + \ + data.getDiscription() + \;

pstmt = connection.prepareStatement(sql); pstmt.execute(); return true; }

public boolean insert(StuData data) throws SQLException { sql = \

+ data.getStu_id() + \ + data.getS_name() + \ + data.getSex() + \ + data.getBirthday() + \

12

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值