samedi 2 septembre 2017

Private variable in java [duplicate]

This question already has an answer here:

I have created a function and added a previous declared global variable called german - inside function I have assigned a value of "german" to it.(The name of class is GamesView) Here is the code:

private void btnGermanActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:

    Locale l = new Locale("de", "DE");
    ResourceBundle r = ResourceBundle.getBundle("internacionalizacija_netbeans2/Bundle", l);
    german = "german";

    btnGerman.setText(r.getString("GamesView.btnGerman.text"));
    btnFrancuski.setText(r.getString("GamesView.btnFrancuski.text_1"));
    btnKineski.setText(r.getString("GamesView.btnKineski.text_1"));
    jLabel1.setText(r.getString("GamesView.jLabel1.text"));

}  

Then in another class I have called above class where is my german variable and then I have used if statement to check if(view.german == "german")

public static void spremiUtakmice(Games games){
    GamesView view = new GamesView();      
    try{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/internacionalizacija?useUnicode=true&characterEncoding=UTF-8","root","");

        String sql = "INSERT INTO utakmice(tim1, tim2, datum, komentar_hrvatski, komentar_njemacki, komentar_francuski, komentar_kineski) VALUES(?,?,?,?,?,?,?)";
        PreparedStatement stmt = conn.prepareStatement(sql);
        //stmt.execute("set names 'utf8'");

        stmt.setString(1, games.getTim1());
        stmt.setString(2, games.getTim2());
        stmt.setString(3, games.getDatum());
        stmt.setString(4, "");

        if(view.german == "german"){
        stmt.setString(5, games.getKomentar_njemacki());
        stmt.setString(6, "");
        stmt.setString(7, "");
        }

If statement doesn't work because view.german is not euqal to "german" - I get value of null, I think I can't access private variable, I need if statement to be true so the code inside block can run.

Aucun commentaire:

Enregistrer un commentaire