java中JTextField的setText()问题 5
publicclassAextendsJFrame{privateJTextFieldtext1;Strings2,text1_1;classA(){.....text1...
public class A extends JFrame{
private JTextField text1;
String s2,text1_1;
class A(){
.....
text1=new JTextField(10);
text1_1=fangfa(InputCardnum.s1);
text1.setText(text1_1+"");
System.out.println(text1_1);
}
String fangfa(String a) throws Exception{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ATMdemo","sa","123456");
Statement stat=conn.createStatement();
String sql="select yue from yinhangka where kahao= '"+a+"'";
ResultSet rs=stat.executeQuery(sql);
System.out.println("222");
while(rs.next()){
s2=rs.getString("yue");
System.out.println(s2);
}
}
return s2;
}
我想要text1.setText(text1_1);这句执行,然后text1的值是fangfa的返回值,可是总是不成功,可是两句System.out.println语句都有执行,而且输出我想要的值了,请问是我setText()用错了么,还是什么,求解答。。。。 展开
private JTextField text1;
String s2,text1_1;
class A(){
.....
text1=new JTextField(10);
text1_1=fangfa(InputCardnum.s1);
text1.setText(text1_1+"");
System.out.println(text1_1);
}
String fangfa(String a) throws Exception{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ATMdemo","sa","123456");
Statement stat=conn.createStatement();
String sql="select yue from yinhangka where kahao= '"+a+"'";
ResultSet rs=stat.executeQuery(sql);
System.out.println("222");
while(rs.next()){
s2=rs.getString("yue");
System.out.println(s2);
}
}
return s2;
}
我想要text1.setText(text1_1);这句执行,然后text1的值是fangfa的返回值,可是总是不成功,可是两句System.out.println语句都有执行,而且输出我想要的值了,请问是我setText()用错了么,还是什么,求解答。。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询