主界面如下。
9
〈5〉重要代码如下。 由于代码太多,以下只写代码1的很小一部分”对数据库的操作:
公共类连接JDBC {
protectedstaticconnectionconnection=空; 私密连接con=null; 私有结果RS=null;
私有esultsetmetadatarsmd=空值; publicconneJDBC((try ) class.forname (connection=driver manager.getconnection () () ) ) ) ) ) ) ) )
} catch (Java.lang.classnotfoundexceptionclassnotfound ) { classnotfound.printStackTrace ); }catch(Java.sql .令人敬畏的诺里SQL ) { sql.printStackTrace ); }
公共连接获取() { return connection; }
10
publicvectorselectsql (字符串SQL ) { Vector vdata=new Vector ); try { RS=connection.preparestatement (SQL ).executeQuery ); rsmd=RS.get元数据(; while(RS.next ) ) vdata.addelement ) RS.getobject(1); (} catch )可怕的诺里e ) { e.printStackTrace ); }
返回数据; }
公共字符串选择(字符串SQL ) { ResultSet rs=null;
resultset元数据rsmd=null; try { RS=connection.preparestatement (SQL ).executeQuery ); rsmd=RS.get元数据(; if(RS.next ) )返回(字符串) RS.getobject(1; (} catch )可怕的诺里e ) { e.printStackTrace ); }
返回空值; }
publicbooleanintable (string user,String pa ) throws害怕的紫菜) { Statement stmt=null;
RS=connection.preparestatement (SQL ).executeQuery ); if(RS.next ) )返回真; else返回假; }
2 )表格模型处理:
publicclasssqltablemodelextendsdefaulttablemodel {私有连接=null; 私有结果RS=null;
私有esultsetmetadatarsmd=空值;
publicsqltablemodel (string sqlstr,String[] name ) { con=new ConneJdbc ).getCon );
11
try{
RS=con.preparestatement(SQLSTR ).executeQuery ); rsmd=RS.get元数据(;
for(intI=0; Iwhile(RS.next ) ) }
矢量vdata=new vector (;
for(intI=1; i=rsmd.getColumnCount (; I ) vdata.addelement(RS.getobject ) I ); }
addrow(vdata ); }
}catch(Java.sql .令人敬畏的诺里SQL ) { sql.printStackTrace ); }finally { try { con.close (; (} catch )可怕的诺里e ) { e.printStackTrace ); }
}
3 ) up数据库的部分代码:
publicclassupdatedatebaseextendsconnejdbc {专用测试语句=null;
privatepreparedstatementpstmt=null; 私有字符串信息=null; 私有字符串SQL;
公共更新数据库
publicbooleaninsert (depdatadata ) throws害怕的诺里)。
ptmt=connection.preparestatement (SQL; pstmt.execute (; 返回真; }
publicbooleaninsert (studatadata ) throws害怕的诺里({ sql=
12