继往开来 吐故纳新
日历
网志分类
· 所有网志 (990)
· 个人作品 (62)
· 软件设计 (33)
· 面向对象编程 (22)
· JavaAPI (39)
· Java开源工具 (31)
· Swing (34)
· Java语法细节 (39)
· 样式表CSS (12)
· XML (10)
· J2EE(JavaEE) (23)
· 算法数据结构 (64)
· 正则表达式 (4)
· 软件知识 (6)
· Java线程 (9)
· Web开发.Jsp/Servlet/Struts (20)
· 程序随想录 (7)
· Spring (5)
· Hibernate (7)
· J2SE 高级 (2)
· J2SE 高级 (0)
· Web开发.Ajax (16)
· Web开发.JavaScript (43)
· DB4O (2)
· Web开发.CSS/Html (22)
· C# (20)
· ERP (4)
· JDBC (1)
· 编程资源 (16)
· 编程感悟 (29)
· DB/Sql (13)
· VB (29)
· VC (2)
· 桌面脚本 (3)
· 新兴软件 (3)
· 英语学习 (21)
· 网文转载 (159)
· 职场风云 (39)
· 诗词歌赋 (32)
· 生活感言 (77)
· 奇文共赏 (13)
· 财经纵横 (6)
· 未分类 (11)
站内搜索
友情链接
· 歪酷博客
· 我的歪酷 非非共享界
· 偶要雷锋
· 豆瓣
· nczonline
· 当当网
· easyjf中文站
· Donews
· 天极Java文章列表
· W3CSchool
· taiten的BLOG
· Dojo中国
· Dojo
· Extjs.com
· Lifehack中文网志
· JaveEye的一个AS专题
· Banq's JDon
· Java 中文网址大全
· 梦想Java
· 360Doc个人图书馆
· java开源大全
· 我在硅谷动力的软件下载站
· 站长中国
· 随意贴
· CSS教学素材站
· java 参考中文站
· 面向构件与SOA社区
· 彩字生成
· 派派小说论坛
· 如坐春风
· 英语学习网
· BBC CHina
· www.dlbang.com
· 古文竖排格式在线转化工具
· 免费家谱
· 图片上传基地
· 风景壁纸
· 和风细雨
· MyC#BlogInCsdn

订阅 RSS

0207473

歪酷博客

开此博一为经验积累,二为资料收集,三为同道交流,四为资源共享.
« 上一篇: 【翻译】java.lang包API 下一篇: 【转贴】笑傲职场-如何在工作中获得影响力、权力与晋升 »
Junglesong @ 2007-03-01 17:07

本文翻译自Java年鉴1.4

判断数据库是否支持事务


    try {
        DatabaseMetaData dmd = connection.getMetaData();
        if (dmd.supportsTransactions()) {
            // Transactions are supported
        } else {
            // Transactions are not supported
        }
    } catch (SQLException e) {
    }

处理SQL异常
下例说明了如何取出SQL异常信息
This example demonstrates how to retrieve the information in a SQLException.
    try {
        // Execute SQL statements...
    } catch (SQLException e) {
        while (e != null) {
            // 取出表示异常原因的可读信息 Retrieve a human-readable message identifying 
// the reason for the exception String message = e.getMessage(); // This vendor-independent string contains a code that identifies // the reason for the exception. // The code follows the Open Group SQL conventions. String sqlState = e.getSQLState(); // Retrieve a vendor-specific code identifying the reason for the exception. int errorCode = e.getErrorCode(); // If it is necessary to execute code based on this error code, // you should ensure that the expected driver is being // used before using the error code. // Get driver name String driverName = connection.getMetaData().getDriverName(); if (driverName.equals("Oracle JDBC Driver") && errorCode == 123) { // Process error... } // 取得下一个异常 The exception may have been chained; process the next chained exception e = e.getNextException(); } }
设定从数据库取出的记录数
取出的固定大小可以用于statement上,这样取出的结果集都是一样的大小;
固定大小也可用于ResultSet上,这样下次的记录数就是设定的大小.
以下是使用的例子
try {
        // Get the fetch size of a statement
        Statement stmt = connection.createStatement ();
        int fetchSize = stmt.getFetchSize();
   
        // Set the fetch size on the statement
        stmt.setFetchSize(100);
   
        // Create a result set
        ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");
   
        // Change the fetch size on the result set
        resultSet.setFetchSize(100);
    } catch (SQLException e) {
    }

取得结果集的列名
try {
        // Create a result set
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM my_table");
   
        // Get result set meta data
        ResultSetMetaData rsmd = rs.getMetaData();
        int numColumns = rsmd.getColumnCount();
   
        // 取得列名,字段序列默认从一开始 Get the column names; column indices start from 1
        for (int i=1; i<numColumns+1; i++) {
            String columnName = rsmd.getColumnName(i);
   
            // Get the name of the column's table name
            String tableName = rsmd.getTableName(i);
        }
    } catch (SQLException e) {
    }












最新评论

2007-03-01 17:31 网址: http://jiyibei.ycool.com/

Fascinated by the title.
This is a good blog!
First to here.have a good time!


2007-03-01 18:13 网址: http://junglesong.ycool.com/

谢谢夸奖,欢迎常来指教.



chen

2007-03-03 18:07

那是相当好了  哈哈


评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定