您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍了jdbc.utils QueryRunner的建档使用示例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
package com.jdbc.test; import java.sql.*; import java.util.List; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.ResultSetHandler; import org.apache.commons.dbutils.handlers.BeanHandler; import org.apache.commons.dbutils.handlers.BeanListHandler; public class OdbcTest { @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String[] args) { Connection conn =null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.249.137:1521:hgs","hgs","hgs"); //DriverManager.getConnection("jdbc:oracle:thin:@192.168.249.137:1521:hgs","hgs","hgs"); //Class.forName("oracle.jdbc.driver.OracleDriver"); //Connection connection = null; //connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.249.137:1521:hgs","hgs","hgs"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } QueryRunner qr = new QueryRunner(); ////////////////////查询 try { List<Animals> ai = qr.query(conn, "select atype,averageage from animals",new BeanListHandler<Animals>(Animals.class)); for(Animals a : ai){ System.out.println("atype: "+a.getAtype() +" avgage: "+a.getAverageage()); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ////////////////////////////////////插入 try { Object[] params= {"man",78}; //qr.insert(conn, "insert into animals(atype,averageage) values(?,?)", new BeanHandler<Animals>(Animals.class), params); qr.update(conn, "insert into animals(atype,averageage) values(?,?)", params); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ///删除 try { Object[] params= {"man",78}; //qr.insert(conn, "insert into animals(atype,averageage) values(?,?)", new BeanHandler<Animals>(Animals.class), params); qr.update(conn, "delete from animals"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
感谢你能够认真阅读完这篇文章,希望小编分享的“jdbc.utils QueryRunner的建档使用示例”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。