i'm building this program using javafx and sqllite i have button in fxml with fx:id button1 and onAction: WriteToSql
package valgykla;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.event.ActionEvent;
/**
* FXML Controller class
*
* @author Lukas
*/
public class MeniuController implements Initializable {
@FXML
private Button button1;
@FXML
public static void WriteToSql(ActionEvent sql){
Connection con = null;
PreparedStatement prSt = null;
try {
Class.forName("org.sqlite.JDBC");
con = DriverManager.
getConnection("jdbc:sqlite:database.db");
String query = "insert into Meniu(name,code) values(?,?)";
prSt = con.prepareStatement(query);
prSt.setString(1, "jack");
prSt.setString(12, "02545");
int count = prSt.executeUpdate();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
}
// TODO Auto-generated catch block
finally{
try{
if(prSt != null) prSt.close();
if(con != null) con.close();
} catch(Exception ex){}
}
}
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
sadly I get error
Caused by: javafx.fxml.LoadException: Error resolving onAction='#WriteToSql', either the event handler is not in the Namespace or there is an error in the script.
file:/C:/Users/Lukas/Desktop/lukasX/Valgykla/dist/run1382723305/Valgykla.jar!/valgykla/Meniu.fxml:29