---
title: "jdbc建单查询遍历查询的列"
author: "农村哥们"
date: "2010-08-05T18:36:21Z"
tags: []
categories: ["编程语言"]
slug: "jdbc"
draft: false
lastmod: "2010-08-05T18:36:21Z"
id: 730289
url: "https://weareold.iteye.com/blog/730289"
---

```java

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){
	    	}
	    } 
	}

```