所以我得到了這些字符串我我的主文件名爲「登錄」的是類從另一個文件中調用字符串
public JPasswordField passfield;
public JTextField userfield;
public JTextField hostfield;
public String host;
public String user;
public String pwd;
JButton buttoncon = new JButton("Connect");
//buttoncon.addActionListener(buttonconClick());
buttoncon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
buttonconClick();
}
});
public void buttonconClick() {
if(hostfield.getText().length()==0)
JOptionPane.showMessageDialog(null, "Tomt ip felt");
else if(userfield.getText().length()==0)
JOptionPane.showMessageDialog(null, "Tomt brukernavn felt");
else if(passfield.getPassword().length==0)
JOptionPane.showMessageDialog(null, "Tomt passord felt");
else{
host = hostfield.getText();
host = "jdbc:mysql://" + host;
user = userfield.getText();
char[] pass = passfield.getPassword();
pwd = String.copyValueOf(pass);
}
則連接到DB
我需要在我第二次來調用這些字符串文件我也有文件importet
import test.Login;
JButton Worldselect = new JButton("World");
Worldselect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
Login mysqlcon = new Login();
String hostcon = mysqlcon.host;
hostcon = "jdbc:mysql://" + hostcon;
String usercon = mysqlcon.user;
String pwdcon = mysqlcon.pwd;
Connection conn = DriverManager.getConnection(hostcon,usercon,pwdcon);
但是,當我這樣做,他們retun emty,爲什麼呢?
如果它可以很容易地適合您的問題,請發佈「登錄」的完整代碼。 –
你登錄代碼的例子不能編譯。我的猜測是你遺漏了一些必不可少的東西。這些值在哪裏初始化? – hotzst
你試過調試過嗎? –