DBUTILS

public static void main(String[] args) throws SQLException, ClassNotFoundException {
		Class.forName("org.apache.derby.jdbc.ClientDriver");
		Connection jdbcConnection = DriverManager.getConnection("jdbc:derby://localhost:1527/myDB", "root", "lin");
		
		ResultSetHandler handler = new ResultSetHandler(){
			@Override
			public Object handle(ResultSet rs) throws SQLException {
				if(!rs.next()){
					return null;
				}
				
				Object[] objects = new Object[rs.getMetaData().getColumnCount()];
				for (int i = 0; i < objects.length; i++) {
					objects[i] = rs.getObject(i+1);
				}
				return objects;
			}
		};
		
		//runner
		QueryRunner runner = new QueryRunner();
		Object[] objects = (Object[]) runner.query(jdbcConnection, "select * from demouser", handler);
		System.out.println(objects.length);
		
		for (Object object : objects) {
			System.out.println(ArrayUtils.toString(object));;
		}
		
	}

 

 

你可能感兴趣的:(apache,jdbc,Derby)