简单的JDBC应用程序for Java DB - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-25
"update derbyDB set num=300, addr=''Lakeshore Ave.'' where num=180"); System.out.println("Updated 180 Grand to 300 Lakeshore"); /* 查询并校验结果. */ ResultSet rs = s.executeQuery( "SELECT num, addr FROM derbyDB ORDER BY num"); if (!rs.next()) { throw new Exception("Wrong number of rows"); } if (rs.getInt(1) != 300) { throw new Exception("Wrong row returned"); } if (!rs.next()) { throw new Exception("Wrong number of rows"); } if (rs.getInt(1) != 1910) { throw new Exception("Wrong row returned"); } if (rs.next()) { throw new Exception("Wrong number of rows"); } System.out.println("Verified the rows"); s.execute("drop table derbyDB");//删除表 System.out.println("Dropped table derbyDB"); rs.close(); s.close(); System.out.println("Closed result set and statement"); conn.commit(); conn.close(); System.out.println("Committed transaction and closed connection"); boolean gotSQLExc = false; if (framework.equals("embedded")) { try { DriverManager.getConnection("jdbc:derby:;shutdown=true");//关闭数据库服务 } catch (SQLException se) { gotSQLExc = true; } if (!gotSQLExc) { System.out.println("Database did not shut down normally"); } else { System.out.println("Database shut down normally"); } } } catch (Throwable e) { System.out.println("exception thrown:"); if (e instanceof SQLException) { printSQLError((SQLException) e); } else { e.printStackTrace(); } } System.out.println("SimpleApp finished"); } static void printSQLError(SQLException e) { while (e != null) { System.out.println(e.toString()); e = e.getNextException(); } } private void parseArguments(String[] args) { // System.setProperty("derby.system.home", "c:\\DBdata");//这样可以设置数据库数据的存放目录 int length = args.length; for (int index = 0; in |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于简单的JDBC应用程序for Java DB - 编程入门网的所有评论