Resultset.getString("COLUMN_NAME")的COLUMN_NAME是怎么来的,书上这么写,我不明白作者是怎么知道用它的? 这个是用来得到此列名的内容的,要得到列名,需要用MetaData 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下例将以sqlserver2000为例子,说明一下怎么得到列名:String connStr="jdbc:microsoft:sqlserver://hello:1433;DatabaseName=pubs"; String connDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; String lsql="select * from authors"; try { Class.forName(connDriver); Connection con = DriverManager.getConnection(connStr, "sa", "iloveyou"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery(lsql);---------------------------------------------------------- 虚线中间代码将打顺序找印出来表authors的字段名 ResultSetMetaData md=rs.getMetaData(); for (int i=1;i<=md.getColumnCount();i++){ System.out.println(md.getColumnName(i)); }----------------------------------------------------------- } catch (SQLException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } } xaxyt(笨笨) 的例子已经很明确了 这里的列名是你自己定义的数据库,在你的Database对象和DataResult对象连接之后便可以看到! 不对呀,我的列名是“FoodKey”不是COLUMN_NAME,为什么说它是我的列名? COLUMN_NAME并不是你的列名,而是列名的英文,在这里是指你传入的参数是“COLUMN_NAME”,也就是说列名. 如果你的列名为FoodKey.就应该写为:rs.getString("FoodKey");当然假设你的字段FoodKey的类型为字符串. 可以把qq好友的隐身状态的软件的原理是什么啊,求指点 这样的一棵树该如何生成? file.listFiles()内存溢出如何解决? 关于正则表达式的奇怪问题!! 怎么样从数据库里面的表的内容生成一张列表显示在jsp页面里 请教高手们, Eclipse下java执行通过,拿到linux下hive中CREATE TEMPORARY FUNCTION失败 计算器功能的实现?怎样在循环监听中实现加减乘除... JAVA mail!邮件接受下来如何放!放在什么地方! 请教各位高手!!!--关于SWING 类库 打印问题 时间段检索问题!!!!
String connStr="jdbc:microsoft:sqlserver://hello:1433;DatabaseName=pubs";
String connDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String lsql="select * from authors";
try {
Class.forName(connDriver);
Connection con = DriverManager.getConnection(connStr, "sa", "iloveyou");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(lsql);
----------------------------------------------------------
虚线中间代码将打顺序找印出来表authors的字段名
ResultSetMetaData md=rs.getMetaData();
for (int i=1;i<=md.getColumnCount();i++){
System.out.println(md.getColumnName(i));
}
-----------------------------------------------------------
}
catch (SQLException ex) {
ex.printStackTrace();
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
就应该写为:rs.getString("FoodKey");
当然假设你的字段FoodKey的类型为字符串.