Example of archiving and use of jdbc.utils QueryRunner
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!