这篇文章主要介绍了jdbc.utils QueryRunner的建档使用示例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
成都创新互联是创新、创意、研发型一体的综合型网站建设公司,自成立以来公司不断探索创新,始终坚持为客户提供满意周到的服务,在本地打下了良好的口碑,在过去的10年时间我们累计服务了上千家以及全国政企客户,如软装设计等企业单位,完善的项目管理流程,严格把控项目进度与质量监控加上过硬的技术实力获得客户的一致赞扬。
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 { Listai = qr.query(conn, "select atype,averageage from animals",new BeanListHandler (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.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.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的建档使用示例”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!