I have this problem, when i Edit run configuration.
Error: Could not find or load main class books Caused by: java.lang.ClassNotFoundException: books
This is the main class where i compile the project:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class books extends Application {
@Override
public void start(Stage stage)throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(books.class.getResource("sample/book.fxml"));
Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("Library");
stage.setScene(scene);
stage.show();
}
public static void main (String[] args ){launch(args);}
}
Its my fxml Controller class:
package sample;
import Dialog.AlertDialog;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import java.net.URL;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ConcurrentModificationException;
import java.util.ResourceBundle;
public class FXMLDocumentController implements Initializable {
@FXML
private Button butt_add;
@FXML
private TextField txt_codeclass;
@FXML
private TextField txt_codepublish;
@FXML
private TextField txt_databook;
@FXML
private TextField txt_namebook;
private Connection conn = null;
private PreparedStatement pat = null;
@FXML
void handleAddbook(ActionEvent event) throws SQLException {
String sql = "Insert into books(bookname,idPublish,Datebook,idclass)
Values(?,?,?,?)";
String bookname = txt_namebook.getText();
String publish = txt_codepublish.getText();
Date date = Date.valueOf(txt_databook.getText());
String IDclass = txt_codeclass.getText();
try {
pat = conn.prepareStatement(sql);
pat.setString(1,bookname);
pat.setString(2,publish);
pat.setDate(3,date);
pat.setString(4,IDclass);
int i = pat.executeUpdate();
if (i==1)
//System.out.println("Data Inserted Successfully");
AlertDialog.display("info","Data Insert Successfuly");
} catch (SQLException e) {
e.printStackTrace();
}
finally {
pat.close();
}
}
@Override
public void initialize (URL url, ResourceBundle rb){
conn = SQLConnect.peartConnection();
}
}
This is connection with sql server studio, And it was worked.
package sample;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;
public class SQLConnect {
public static Connection peartConnection() {
Connection conn = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;databaseName=Library;username=adminn;password=bahytn001";
conn = DriverManager.getConnection(url);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return conn;
}
}
I created special class module-info.java and write javafx libraries:
module application {
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
requires javafx.base;
requires java.sql;
opens sample;
}
Please help me don't give me any links please. I will be very grateful. I work with Intellij 2021.2.2 JDK 14, JDBC 11