有2个类第一个类里有这样的代码:
package first;
import java.sql.*;
public class a{
public static String getCardId() {
String a = "";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
JOptionPane.showMessageDialog(null, ce, "错误",
JOptionPane.ERROR_MESSAGE);
}
try {
String url = "jdbc:odbc:NetBar";
String str = "select * from Record where Computer='1'
Connection con = DriverManager.getConnection(url, "Record",
"123456");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(str);
while (rs.next()) {
a = rs.getString("CardId");
}
s.close();
con.close();
} catch (SQLException se) {
JOptionPane.showMessageDialog(null, se + "101010", "错误",
JOptionPane.ERROR_MESSAGE);
}
return a;
}
}
我在第2个类(这个类在第2个包里)里有一个jTextField;我将这个jTextField的Text设置为jTextField.setText(a.getCardId());本来我认为这个jTextField里应该显示的是a的值(a的值是111),可是实际上传递过来的值却是空的,这是为什么啊?