欢迎来到天天文库
浏览记录
ID:14326498
大小:93.50 KB
页数:43页
时间:2018-07-27
《java数据库操作大全》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Java数据库操作大全?1.提取单条记录/*importjava.sql.*;privateConnectionconn=null;privateStatementstmt=null;privateResultSetrs=null;*/try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringurl="jdbc:odbc:%%1";conn=DriverManager.getConnection(url,%%2,%%3);stmt=conn.createStatement();rs=stmt.executeQue
2、ry(%%4);rs.next();int%%5=rs.getInt(%%6);//String%%5=rs.getString(%%6);}catch(Exceptione){e.printStackTrace();}finally{try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(conn!=null)conn.close();}catch(SQLExceptione){e.printStackTrace();}}2.单值比较/*importjava.sql.*;privateConnectionc
3、onn=null;privateStatementstmt=null;privateResultSetrs=null;*/try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringurl="jdbc:odbc:%%1";conn=DriverManager.getConnection(url,%%2,%%3);stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);rs=stmt.executeQu
4、ery(%%2);rs.next();int%%6=rs.getInt(%%7);if(%%6==%%4){%%5}}catch(Exceptione){e.printStackTrace();}finally{try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(conn!=null)conn.close();}catch(SQLExceptione){e.printStackTrace();}}3.显示表格/*importjava.awt.*;importjavax.swing.*;importjava
5、.sql.*;importjavax.swing.table.*;privateConnectionconn=null;privateStatementstmt=null;privateResultSetrs=null;*/String[]colHeads=newString[]{"au_fname","Phone","City"};try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringurl="jdbc:odbc:%%1";conn=DriverManager.getConnection(url,%%2,%
6、%3);stmt=conn.createStatement();rs=stmt.executeQuery("SelectCount(*)Asau_countFrom%%5");rs.next();intiCount=rs.getInt("au_count");Object[][]data=newObject[iCount][];inti=0;rs=stmt.executeQuery("Select*From%%5");while(rs.next()){data[i]=newObject[iCount];data[i][0]=rs.getString("au_fnam
7、e");data[i][1]=rs.getString("Phone");data[i][2]=rs.getString("City");i++;}JTabletable=newJTable(data,colHeads);JScrollPanejsp=newJScrollPane(table);this.add(jsp);}catch(Exceptione){e.printStackTrace();}finally{try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(conn!=null)conn.c
此文档下载收益归作者所有