Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of archiving and use of jdbc.utils QueryRunner

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the use of jdbc.utils QueryRunner file examples, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

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 blocke.printStackTrace ();} QueryRunner qr = new QueryRunner (); / query try {List ai = 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 blocke.printStackTrace ();} / / insert 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 blocke.printStackTrace ();} / / delete 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 blocke.printStackTrace ();} try {conn.close ();} catch (SQLException e) {/ / TODO Auto-generated catch blocke.printStackTrace () } Thank you for reading this article carefully. I hope the article "examples of filing and use of jdbc.utils QueryRunner" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report