方式一:
简单的使用JDBC
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
List list = new ArrayList();
try{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(SQL); //这里的SQL就是你的查询语句
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
Map map = new HashMap();
for (int i = 1; i <= columnCount; i++) {
map.put(md.getColumnName(i), rs.getObject(i));
}
list.add(map);
}
}catch(SQLException e)
{
e.printStackTrace();
}
return list;
我自己写的,不管什么SQL,都可以查询获取到一个list
CallableStatement stme=connection.prepareCall("select p.item,p.type1,p.name,p.lvl,p.item_mode,p.type2,p.up_item from pub_itemcode p where p.type1=?
");
stme.setInt(1, 1);
后面的代码就是取ResultSet遍历,不再累述