java连接sql查询不显示结果,菜鸟急求啊
classProDao{publicstaticObject[][]findAllUser(){Object[][]stus=null;try{DBUtildb=newD...
class ProDao
{
public static Object[][] findAllUser(){
Object[][] stus=null;
try{
DBUtil db = new DBUtil();
db.getConnection();
String findsql = "select * from [user]";
String[] params =null;
ResultSet rs= db.executeQuery(findsql, params);
int rows=0;
while(rs.next()){
rows++;
}
stus=new Object[rows][6];
rs.beforeFirst();
int row=0;
while(rs.next()){
for(int i=0;i<6;i++){
stus[row][i]=rs.getString(i+1);
return stus;
}
row++;
}
db.closeAll();
}catch(Exception e){}
return stus;
}
——————————————————————————————————————————————
class ProPan0 extends JPanel
{
String[] tabheadname={" 卡号 ","密码","余额","电话","性别","身份证"};
JTextField tsearch=new JTextField(25);
JComboBox csearch=new JComboBox(new String[]{"卡号","手机号","身份证号"});
JButton bsearch=new JButton("查询");
JButton bedit=new JButton("编辑");
JButton bdelete=new JButton("删除");
final DefaultTableModel tableModel;
final JTable jTable;
Object[][] stulist=ProDao.findAllUser();
public ProPan0()
{
tableModel = new DefaultTableModel(stulist,tabheadname);
jTable=new JTable(tableModel)
{
public boolean isCellEditable(int row, int column)
{
return false;
}//表格不允许被编辑
};
JScrollPane pj=new JScrollPane(jTable);
//查找按钮
bsearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
Object[][] stulist=ProDao.findUser(csearch.getSelectedIndex(),tsearch.getText());
//System.out.println(stulist.length);
tableModel.setDataVector(stulist,tabheadname);
}
});
我在数据库里能查询到完整的结果,但是在java里面显示不出来,不知道是怎么回事,急求帮助啊 展开
{
public static Object[][] findAllUser(){
Object[][] stus=null;
try{
DBUtil db = new DBUtil();
db.getConnection();
String findsql = "select * from [user]";
String[] params =null;
ResultSet rs= db.executeQuery(findsql, params);
int rows=0;
while(rs.next()){
rows++;
}
stus=new Object[rows][6];
rs.beforeFirst();
int row=0;
while(rs.next()){
for(int i=0;i<6;i++){
stus[row][i]=rs.getString(i+1);
return stus;
}
row++;
}
db.closeAll();
}catch(Exception e){}
return stus;
}
——————————————————————————————————————————————
class ProPan0 extends JPanel
{
String[] tabheadname={" 卡号 ","密码","余额","电话","性别","身份证"};
JTextField tsearch=new JTextField(25);
JComboBox csearch=new JComboBox(new String[]{"卡号","手机号","身份证号"});
JButton bsearch=new JButton("查询");
JButton bedit=new JButton("编辑");
JButton bdelete=new JButton("删除");
final DefaultTableModel tableModel;
final JTable jTable;
Object[][] stulist=ProDao.findAllUser();
public ProPan0()
{
tableModel = new DefaultTableModel(stulist,tabheadname);
jTable=new JTable(tableModel)
{
public boolean isCellEditable(int row, int column)
{
return false;
}//表格不允许被编辑
};
JScrollPane pj=new JScrollPane(jTable);
//查找按钮
bsearch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
Object[][] stulist=ProDao.findUser(csearch.getSelectedIndex(),tsearch.getText());
//System.out.println(stulist.length);
tableModel.setDataVector(stulist,tabheadname);
}
});
我在数据库里能查询到完整的结果,但是在java里面显示不出来,不知道是怎么回事,急求帮助啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询