,我怎麼能在private void jButton1
使用myInt
從private void jButton2
?訪問私有函數的變量考慮下面的代碼中的另一個私有函數
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int myInt = (Integer)jSpinner1.getValue();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int b = 0;
int c = myInt;
do {
try {
Object newInstance = Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/rk","root","root");
PreparedStatement ps = (PreparedStatement) con.prepareStatement("INSERT INTO factors VALUES(?,?,?,?,?,?)");
ps.setString(1,jTextField7.getText());
ps.setString(2,jTextField8.getText());
ps.setString(3,jTextField9.getText());
ps.setString(4,jTextField10.getText());
ps.setString(5,jTextField11.getText());
ps.setString(6,jTextField12.getText());
ps.executeUpdate();
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField10.setText("");
jTextField11.setText("");
jTextField12.setText("");
}
catch (Exception e) {
System.out.println(e);
}
b++;
} while(b < my);
}
謝謝這幫了我 – radish