JAVA连接数据库返回输出信息
问题如图输出结果在eclipse上输出了,可是在文本框上出不来publicvoidquery(Stringsqls){Chaxunchaxun1=newChaxun();...
问题如图
输出结果在eclipse上输出了,可是在文本框上出不来
public void query(String sqls)
{
Chaxun chaxun1=new Chaxun();
try{
stmt=dbConn.createStatement();
ResultSet rset=stmt.executeQuery(sqls);
while(rset.next())
{
chaxun1.nameField4.setText(rset.getString(1));
chaxun1.nameField5.setText(rset.getString(2));
chaxun1.nameField6.setText(rset.getString(3));
chaxun1.nameField7.setText(rset.getString(4));
chaxun1.nameField8.setText(rset.getString(5));
for(int i=1;i<=5;i++) {
System.out.print(rset.getString(i)+"\t");
}
System.out.println();
}
这是我数据库类里的查询相关代码
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
String name=nameField3.getText();
S s=new S();
operatedb op1=new operatedb("sa","85791469");
String s1="select * from st1 where name='"+name+"'";
op1.query(s1);
}
}
这是我查询类里的代码
求解 急急急 坐等答案 展开
输出结果在eclipse上输出了,可是在文本框上出不来
public void query(String sqls)
{
Chaxun chaxun1=new Chaxun();
try{
stmt=dbConn.createStatement();
ResultSet rset=stmt.executeQuery(sqls);
while(rset.next())
{
chaxun1.nameField4.setText(rset.getString(1));
chaxun1.nameField5.setText(rset.getString(2));
chaxun1.nameField6.setText(rset.getString(3));
chaxun1.nameField7.setText(rset.getString(4));
chaxun1.nameField8.setText(rset.getString(5));
for(int i=1;i<=5;i++) {
System.out.print(rset.getString(i)+"\t");
}
System.out.println();
}
这是我数据库类里的查询相关代码
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
String name=nameField3.getText();
S s=new S();
operatedb op1=new operatedb("sa","85791469");
String s1="select * from st1 where name='"+name+"'";
op1.query(s1);
}
}
这是我查询类里的代码
求解 急急急 坐等答案 展开
展开全部
把你的查询地方修改一下:
public void actionPerformed(ActionEvent e){
String name=nameField3.getText();
String s1="select * from st1 where name='"+name+"'";
try{
stmt=dbConn.createStatement();
ResultSet rset=stmt.executeQuery(sqls);
if(rset.next())
{
nameField4.setText(rset.getString(1));
nameField5.setText(rset.getString(2));
nameField6.setText(rset.getString(3));
nameField7.setText(rset.getString(4));
nameField8.setText(rset.getString(5));
}
}
public void actionPerformed(ActionEvent e){
String name=nameField3.getText();
String s1="select * from st1 where name='"+name+"'";
try{
stmt=dbConn.createStatement();
ResultSet rset=stmt.executeQuery(sqls);
if(rset.next())
{
nameField4.setText(rset.getString(1));
nameField5.setText(rset.getString(2));
nameField6.setText(rset.getString(3));
nameField7.setText(rset.getString(4));
nameField8.setText(rset.getString(5));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询