shangjun.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 9
    下载次数
  • 2005-06-17 09:59
    上传日期
本文件是java连接sql数据库并且能够进行显示表内容
shangjun.rar
  • www.pudn.com.txt
    218B
  • shangjun.java
    3.1KB
内容介绍
import java.sql.*; import java.net.URL; public class shangjun { static String url="jdbc:odbc:sj"; public static void main(String[] args) { int j=1; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"sa",""); checkForWarning(con.getWarnings()); DatabaseMetaData dma=con.getMetaData(); System.out.println("\nconnectto"+dma.getURL()); System.out.println("Driver"+dma.getDriverName()); System.out.println("version"+dma.getDriverVersion()); System.out.println(" "); Statement stmt=con.createStatement(); CallableStatement cs=con.prepareCall("{call shangjun(?,?,?,?,?,?,?,?,?,?,?,?)}"); cs.setString(1,"2005-12-12"); cs.setString(2,"b"); cs.setString(3,"b"); cs.setString(4,"b"); cs.setString(5,"b"); cs.setString(6,"b"); cs.setString(7,"b"); cs.setString(8,"b"); cs.setString(9,"b"); cs.setString(10,"b"); cs.setString(11,"b"); cs.setString(12,"b"); cs.executeUpdate(); ResultSet rs=stmt.executeQuery("select * from gjjl"); ResultSetMetaData rsmd=rs.getMetaData(); int i=rsmd.getColumnCount(); for( j=1;j<=i;j++){ if(j>1){System.out.print(",");} System.out.print(rsmd.getColumnName(j)); } System.out.println(""); while(rs.next()) { String ghrq=rs.getDate("ghrq").toString(); String hpid=(rs.getString("hpid")).trim(); String pm=rs.getString("pm").trim(); String gg=rs.getString("gg").trim(); String jx=rs.getString("jx").trim(); String ccsj=rs.getString("ccsj").trim(); String gjsl=rs.getString("gjsl").trim(); String dw=rs.getString("dw").trim(); String ph=rs.getString("ph").trim(); String yxq=rs.getString("yxq").trim(); String ghdw=rs.getString("ghdw").trim(); String bz=rs.getString("bz").trim(); System.out.println(ghrq+" "+hpid+" "+pm+" "+gg+" "+jx+" "+ccsj+" "+gjsl+" "+dw+" "+ph+" "+yxq+" "+ghdw+" "+bz); } rs.close(); stmt.close(); con.close(); } catch(SQLException er) { System.out.println("SQLsata"); while(er!=null) { System.out.println("SQLSata:"+er.getSQLState()); System.out.println("message:"+er.getMessage()); System.out.println("vendor:"+er.getErrorCode()); er=er.getNextException(); System.out.println(""); } } catch(java.lang.Exception ex) { ex.printStackTrace(); } } private static boolean checkForWarning(SQLWarning warn) throws SQLException { boolean rc=false; if (warn!=null) { System.out.println("\n*********Warning*******\n"); rc=true; while(warn!=null) { System.out.println("SQLSata:"+warn.getSQLState()); System.out.println("message:"+warn.getMessage()); System.out.println("vendor:"+warn.getErrorCode()); warn=warn.getNextWarning(); System.out.println(""); } } return rc; } }
评论
    相关推荐