例如我输入 select * from table 直接显示结果,类似与sql查询客户端
//执行select语句
public String getSelect(String sql,int page_sum,int page){
String return_string = ""
try {
ConnOracle dbc = new ConnOracle()
CallableStatement cs = null
ResultSet rs = null
//分页prc
String insql = "{? = call cus_page.cus_pagination(?,?,?)}"
cs = dbc.getConnection().prepareCall(insql)
cs.registerOutParameter(1, OracleTypes.CURSOR)
cs.setString(2, sql)
cs.setInt(3, page_sum)
cs.setInt(4, page)
cs.executeQuery()
rs = (ResultSet) cs.getObject(1)
--获取列
ResultSetMetaData rsmd = rs.getMetaData()
int numColumns = rsmd.getColumnCount()
String[] column = new String[numColumns]
return_string += "<tr align = 'left' bgcolor='#FFDC75'>"
for (int i = 1i <= numColumns i++) {
column[i-1] = rsmd.getColumnName(i)
return_string += "<td>" + rsmd.getColumnName(i) + "</td>"
//System.out.print("字段名:"+rsmd.getColumnName(i))
//System.out.print(" 字段类型:"+rsmd.getColumnTypeName(i))
//System.out.print(" 字段类型对应java类名:"+rsmd.getColumnClassName(i))
//System.out.print(" 显示长度:"+String.valueOf(rsmd.getColumnDisplaySize(i)))
//System.out.println()
}
return_string += "</tr>"
while(rs.next()){
return_string += "<tr align = 'left'>"
for(int i=0 i<numColumns i++){
return_string += "<td>" + rs.getString(rsmd.getColumnName(i+1)) + "</td>"
}
return_string += "</tr>"
}
} catch (Exception e) {
ErrorLog.SetLog(e.getMessage() + ">>>sql = " + sql, this.getClass().getName()+"."+new Exception().getStackTrace()[0].getMethodName())
return_string = "<tr><td>"+ e.getMessage() +"</td></tr>"
}
return return_string
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)