Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
} String getString(int columnIndex)
Gets the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.String getString(String columnName)
Gets the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
} String getString(int columnIndex)
Gets the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.String getString(String columnName)
Gets the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.
String [] str=null;
while(rs.next())
{
for(int i=0;i<field.length;i++)
{
str[i]=rs.getString(字段名); //这里该怎样写???
}
}
上面的兄弟,我没看懂你的意思
String name=new String();
id="id";
name="name";
while(rs.next()){
System.out.println(rs.getString(id));
System.out.println(rs.getString(name));
}
String [] str=null;
while(rs.next())//这里应该用if,如果用while,是否结果集中有多条,则下边一定出错
{
for(int i=0;i<field.length;i++)
{
str[i]=rs.getString(field[i]);
}
}
比如,field[0]="ID",field[1]="Name";
也可以使用,str[i]=rs.getString(i+1);
i+1代表数据表中依次的字段位置。
结果集里有许多条,而且每条显示的字段都field[]数组决定 都要显示的
所以一定要用while
你有什么好的办法呢???
String [] str=null;
while(rs.next())
{
for(int i=0;i<field.length;i++)
{
str[i]=rs.getString(i+1); //这里该怎样写???
}
}
str[i]=rs.getString(i+1);
这是取啥啊 字段是放在数组里的
......
Statement stmt = con.createStatement;
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
if (rs!=null)
{
while(rs.next())
{
String[] element = new String[2];
element[0] = rs.getString(1);
element[1] = rs.getString(2);
result.add(element);
}
}
最后把result处理就行了
把表中的字段按顺序放到数组里面
然后用rs.getString(i)来取字段的值,i表示整数(i=n表示第n个字段)如果你知道字段的名字,就用rs.getString("filedname");来取值
当然,也可以用vector来做,不用关闭result。
我的意思很简单 我要提取的字段是放在变量里的:rs.getString(变量)
这种格式rs.getString(变量),应该怎样写,
rs.getString(+变量名+)是这样么 ??
rs.getString(filedName);
取得。