Connection conn = this.getSession().connection();
PreparedStatement pt = conn.prepareStatement(sql);
ResultSetMetaData metaData = pt.getMetaData();
........
pt.close();
conn.close();
pt.getMetaData() 报错
java.sql.SQLException: 未执行语句句柄: getMetaData
请问这是什么问题
------解决方案--------------------
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]);
}
}
}
这个是我调试的代码
你试试看
需要修改的
String sql = "";
DataSource ds = null;// 获取数据源