it is reqired to create a DB if not exist and then save the table. The function getConnection() shown in code. The program implemented is as: SAVE button event calls btnsave()->insertrecord()->executequery()->getConnection()
I tested application in following ways:
Inside the eclipse installed on PC1 --> worked well. Database is created and table entries are deleted successfully.
Create the runnable Jar and copied to other laptop PC2 --. works well as in case 1.
Inno setup is installed on PC2. So, used INNO to make installer. Installed n PC2. It seems data is not created. If it is created, I don't know where will it be created in the system ? How to programatically read the database path ?
@FXML private void btnsave(ActionEvent event) throws Exception{ insertrecord(); System.out.println("New Patient Inserted"); } private void insertrecord() throws Exception { try{ String query ="INSERT INTO `newpatient`(patientId,patientName,patientAge,patientGender,patientAddress,patientMobile)"+ "VALUES("+ newpatient_id.getText() +",'" + newpatient_name.getText() + "','"+ newpatient_age.getText() + "'," + "'"+ selectedGender + "','"+ newpatient_address.getText() + "',"+ newpatient_mobile.getText() +")"; executeQuery(query); System.out.println("Saved"); } catch(Exception e) { //System.out.println("Execption in Save"); e.printStackTrace(); } } private void executeQuery(String query) { Connection conn= getConnection(); Statement st; try { st = conn.createStatement(); st.executeUpdate(query); }catch(Exception e){ e.printStackTrace(); } } public static Connection getConnection() { Connection conn = null; try{ Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:patientdata","root",""); System.out.println("data base connection established: "+ conn.toString()); Statement stmt = null; stmt = conn.createStatement(); String pat = "CREATE TABLE if not exists newpatient " + "(patientId INTEGER NOT NULL," + " patientName CHAR(50) NOT NULL, " + " patientAge INTEGER NOT NULL, " + "patientGender CHAR(10) NOT NULL,"+ "patientAddress CHAR(100) NOT NULL,"+ "patientMobile BIGINT(10) NOT NULL)"; System.out.println("newpatient Table Created: "); stmt.executeUpdate(pat); stmt.close(); stmt = conn.createStatement(); String hist = "CREATE TABLE if not exists history " + "(id INTEGER NOT NULL," + " date DATE NOT NULL, " + " start TIME NOT NULL, " + "stop TIME NOT NULL)"; System.out.println("history Table Created: "); stmt.executeUpdate(hist); stmt.close(); return conn }