private static void sel(){
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:ultraeos";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
OraclePreparedStatement ops = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "newcmdb", "newcmdb");
String sqlString = "select * from a_testa t where t.id = ?";
ops = (OraclePreparedStatement)conn.prepareStatement(sqlString);
ops.setString(1, "2a");
rs = ops.getResultSet();
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
while(rs.next()){
for(int i=0;i<columnCount;i++){
rs.getString(i+1);
}
}
} catch (Exception ex2) {
ex2.printStackTrace();
} finally{
try{
if(rs != null){
rs.close();
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}
}catch(Exception e){
}
}
}
jdbc建单查询遍历查询的列
最新推荐文章于 2022-11-24 19:36:29 发布