日期:2014-05-18 浏览次数:20981 次
package cn.com.sparknet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
public class T {
public static void main(String[] args) throws SQLException {
String sql = "";
DataSource ds = null;// 获取数据源
Connection conn = ds.getConnection();
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery(sql);
PreparedStatement pstm = conn.prepareStatement(sql);
ResultSet rs2 = pstm.executeQuery();
ResultSetMetaData metaData = pstm.getResultSet().getMetaData();// pstm.getMetaData();//rs2.getMetaData();
while (rs2.next()) {
System.out.println(rs2.getInt(1) + " " + rs2.getString(2) + " "
+ rs2.getInt(3));
}
int count = metaData.getColumnCount();
System.out.println(count);
String[] name = new String[count];
for (int i = 0; i < count; i++) {
name[i] = metaData.getColumnName(i + 1);
System.out.println(name[i]);
}
}
}