请问怎样从SQL取多个数据 如题,比如说,select * from table where name=nnn如果查询出来有多列数据,怎样取呢?我只能去第一个啊。我用的jdbc,executeQuery()语句我是初学者,请多多指教,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String sql="select * from table where name=nnn";Statement smt = conn.createStatement();ResultSet rs = smt.executeQuery(sql);while (rs.next()) { <%=rs.getString("表的字段名") %>} ResultSet做循环就行了。public List getfx_alarm_setting_info(String mkt_Code) { Connection conn = null; DBConnection dbConnection = null; Statement stmt = null; ResultSet rs = null; String sql = "select * from fx_alarm_setting_info where mkt_Code ='" + mkt_Code + "' and is_valid ='" + 1 + "' "; try { dbConnection = DBFactory .getConnection("CREPOInitAlarmData.getfx_alarm_setting_info"); conn = dbConnection.connection; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { Alarm_CodeList.add(rs.getString("alarm_code")); } } catch (SQLException e) { // TODO: handle exception } catch (ClassException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (!conn.isClosed()) { conn.close(); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } return Alarm_CodeList; } Select 之后返回一个结果集rs(ResultSet)然后用while循环遍历while(rs.next()){ rs.getString(列名) rs.getInt(列名) . . .} java indexof的问题 问题急待解决!!! Java JFrame 关于setDefaultLookAndFeelDecorated鼠标监听 java调用.class文件 接口修饰符 急!急!急!用线程实现一行字滚动的applet小程序 请问大家JBoss的稳定性和效率如何? 初学者:多线程碰到的纠结问题 一个位移问题???????????// 如何用java方法最优雅的实现斐波那契数列 一着面试题,关于代码优化的问题! 这种情况怎么处理啊
Statement smt = conn.createStatement();
ResultSet rs = smt.executeQuery(sql);
while (rs.next()) {
<%=rs.getString("表的字段名") %>
}
Connection conn = null;
DBConnection dbConnection = null;
Statement stmt = null;
ResultSet rs = null; String sql = "select * from fx_alarm_setting_info where mkt_Code ='"
+ mkt_Code + "' and is_valid ='" + 1 + "' ";
try {
dbConnection = DBFactory
.getConnection("CREPOInitAlarmData.getfx_alarm_setting_info");
conn = dbConnection.connection;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
Alarm_CodeList.add(rs.getString("alarm_code"));
}
} catch (SQLException e) {
// TODO: handle exception
} catch (ClassException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (!conn.isClosed()) {
conn.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
return Alarm_CodeList; }
然后用while循环遍历
while(rs.next()){
rs.getString(列名)
rs.getInt(列名)
.
.
.
}