| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1838 人关注过本帖
标题:rs.next()的一点小问题
只看楼主 加入收藏
gxppa2006
Rank: 1
等 级:新手上路
帖 子:178
专家分:0
注 册:2007-2-27
收藏
 问题点数:0 回复次数:6 
rs.next()的一点小问题

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Win extends JFrame implements ActionListener
{
JButton ok,exit;
JTextField name_f,sex_f,age_f,id_f;
Win()
{
ok=new JButton("确定");
exit=new JButton("退出");
name_f=new JTextField();
sex_f=new JTextField();
id_f=new JTextField();
age_f=new JTextField();
Container con=this.getContentPane();
con.setLayout(new GridLayout(5,2));
con.add(new JLabel("ID"));
con.add(id_f);
con.add(new JLabel("姓名"));
con.add(name_f);
con.add(new JLabel("性别"));
con.add(sex_f);
con.add(new JLabel("年龄"));
con.add(age_f);
con.add(ok);
con.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);
setVisible(true);
setSize(400,400);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok)
{

Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:info";
con=DriverManager.getConnection(url,"","");

Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from info");
int id,age;
String name,sex;
while(rs.next()) //这里我想没点一下确定顺序显示一条记录
{ //用while的话只能显示最后一条记录
name=rs.getString("name");//用if的话只显示第一条记录
sex=rs.getString("sex");//用absolute感觉是不会还是怎么的不出结果
id=rs.getInt("id");
age=rs.getInt("age");
name_f.setText(name);
sex_f.setText(sex);
id_f.setText(""+id);
age_f.setText(""+age);
}
}
catch(Exception ew)
{

}
finally
{
try
{
con.close();
}
catch(Exception ee)
{

}
}


}
if(e.getSource()==exit)
{
System.exit(0);
}
}
}


public class DataTest
{
public static void main(String[] args)
{
new Win();
}
}

搜索更多相关主题的帖子: next import JTextField new java 
2007-07-21 08:17
myfor
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:357
专家分:6
注 册:2006-3-13
收藏
得分:0 
回复:(gxppa2006)rs.next()的一点小问题

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Win extends JFrame implements ActionListener
{
String url="jdbc:odbc:info";
Connection con=null;
ResultSet rs = null;

JButton ok,exit;
JTextField name_f,sex_f,age_f,id_f;
Win()
{
ok=new JButton("确定");
exit=new JButton("退出");
name_f=new JTextField();
sex_f=new JTextField();
id_f=new JTextField();
age_f=new JTextField();
Container con=this.getContentPane();
con.setLayout(new GridLayout(5,2));
con.add(new JLabel("ID"));
con.add(id_f);
con.add(new JLabel("姓名"));
con.add(name_f);
con.add(new JLabel("性别"));
con.add(sex_f);
con.add(new JLabel("年龄"));
con.add(age_f);
con.add(ok);
con.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
rs=stmt.executeQuery("select * from info");
setVisible(true);
setSize(400,400);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok)
{
try
{
int id,age;
String name,sex;
if(rs.next()) //这里我想没点一下确定顺序显示一条记录
{ //用while的话只能显示最后一条记录
name=rs.getString("name");//用if的话只显示第一条记录
sex=rs.getString("sex");//用absolute感觉是不会还是怎么的不出结果
id=rs.getInt("id");
age=rs.getInt("age");
name_f.setText(name);
sex_f.setText(sex);
id_f.setText(""+id);
age_f.setText(""+age);
}
}
catch(Exception ew)
{

}
finally
{
try
{
con.close();
}
catch(Exception ee)
{

}
}


}
if(e.getSource()==exit)
{
System.exit(0);
}
}
}


public class DataTest
{
public static void main(String[] args)
{
new Win();
}
}

试试

广告位招租
2007-07-21 10:46
gxppa2006
Rank: 1
等 级:新手上路
帖 子:178
专家分:0
注 册:2007-2-27
收藏
得分:0 
刚我试了  怎么还是不好使  就出来第一条   呵呵

临渊羡鱼,不如退而结网!
2007-07-21 12:46
野蛮女人
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:827
专家分:0
注 册:2007-4-7
收藏
得分:0 
以下是引用gxppa2006在2007-7-21 8:17:23的发言:

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Win extends JFrame implements ActionListener
{

JButton ok,exit;
JTextField name_f,sex_f,age_f,id_f;
Connection con=null;
ResultSet rs;
Win()
{
ok=new JButton("确定");
exit=new JButton("退出");
name_f=new JTextField();
sex_f=new JTextField();
id_f=new JTextField();
age_f=new JTextField();
Container con=this.getContentPane();
con.setLayout(new GridLayout(5,2));
con.add(new JLabel("ID"));
con.add(id_f);
con.add(new JLabel("姓名"));
con.add(name_f);
con.add(new JLabel("性别"));
con.add(sex_f);
con.add(new JLabel("年龄"));
con.add(age_f);
con.add(ok);
con.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);
setVisible(true);
setSize(400,400);

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:info";
con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
rs=stmt.executeQuery("select * from info");
catch(Exception e){

}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok)
{


try
{

rs.next() //这里我想没点一下确定顺序显示一条记录
int id,age;
String name,sex;//用while的话只能显示最后一条记录
name=rs.getString("name");//用if的话只显示第一条记录
sex=rs.getString("sex");//用absolute感觉是不会还是怎么的不出结果
id=rs.getInt("id");
age=rs.getInt("age");
name_f.setText(name);
sex_f.setText(sex);
id_f.setText(""+id);
age_f.setText(""+age);

}
catch(Exception ew)
{

}
finally
{
try
{
con.close();
}
catch(Exception ee)
{

}
}


}
if(e.getSource()==exit)
{
System.exit(0);
}
}

}


public class DataTest
{
public static void main(String[] args)
{
new Win();
}
}

试试

[此贴子已经被作者于2007-7-21 14:03:58编辑过]


[shadow=255,purple,5]好人不长命,祸害一万年![/shadow]
2007-07-21 13:59
gxppa2006
Rank: 1
等 级:新手上路
帖 子:178
专家分:0
注 册:2007-2-27
收藏
得分:0 
  还是不行。。。

临渊羡鱼,不如退而结网!
2007-07-21 20:40
myfor
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:357
专家分:6
注 册:2006-3-13
收藏
得分:0 
回复:(野蛮女人)以下是引用gxppa2006在2007-7-21 8...

我的那个可能是点了一下连接就关闭了的缘故

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Win extends JFrame implements ActionListener
{
String url="jdbc:odbc:info";
Connection con=null;
ResultSet rs = null;

JButton ok,exit;
JTextField name_f,sex_f,age_f,id_f;
Win()
{
ok=new JButton("确定");
exit=new JButton("退出");
name_f=new JTextField();
sex_f=new JTextField();
id_f=new JTextField();
age_f=new JTextField();
Container con=this.getContentPane();
con.setLayout(new GridLayout(5,2));
con.add(new JLabel("ID"));
con.add(id_f);
con.add(new JLabel("姓名"));
con.add(name_f);
con.add(new JLabel("性别"));
con.add(sex_f);
con.add(new JLabel("年龄"));
con.add(age_f);
con.add(ok);
con.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
rs=stmt.executeQuery("select * from info");
setVisible(true);
setSize(400,400);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok)
{
try
{
int id,age;
String name,sex;
if(rs.next()) //这里我想没点一下确定顺序显示一条记录
{ //用while的话只能显示最后一条记录
name=rs.getString("name");//用if的话只显示第一条记录
sex=rs.getString("sex");//用absolute感觉是不会还是怎么的不出结果
id=rs.getInt("id");
age=rs.getInt("age");
name_f.setText(name);
sex_f.setText(sex);
id_f.setText(""+id);
age_f.setText(""+age);
}
}
catch(Exception ew)
{

}

}
if(e.getSource()==exit)
{
try
{
con.close();
}
catch(Exception ee)
{

}
System.exit(0);
}
}
}


public class DataTest
{
public static void main(String[] args)
{
new Win();
}
}

再试试


广告位招租
2007-07-21 20:42
gxppa2006
Rank: 1
等 级:新手上路
帖 子:178
专家分:0
注 册:2007-2-27
收藏
得分:0 
呵呵   感谢楼上拉   

临渊羡鱼,不如退而结网!
2007-07-21 20:50
快速回复:rs.next()的一点小问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019089 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved