System.out.println("hello 2018");
package cn.itcast.javaBean_1;
import java.net.ConnectException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import cn.itcast.JDBCUtil.JDBCUtil;
public class QueryRunnerDemo {
private static Connection con = JDBCUtil.getConnection();
public static void main(String[] args) throws SQLException {
//arryaHandler();
QueryRunner qr = new QueryRunner();
String sql = "SELECT * FROM sort";
List<Object[]> query = qr.query(con, sql, new ArrayListHandler());
for (Object[] objects : query) {
for (Object object : objects) {
System.out.print(object+" ");
}
System.out.println();
}
}
private static void arryaHandler() throws SQLException {
QueryRunner qr = new QueryRunner();
String sql = "SELECT * FROM sort";
Object[] objects = qr.query(con, sql, new ArrayHandler());
for (Object object : objects) {
System.out.println(object);
}
}
}
|
|