0

I am creating an airline ticketing system on my mac and I made a SQLite database for random flight times to be shown on a Jtable after a button is clicked but when I go to the folder that the database is in it says that the database cannot be found when I clearly see it in the file.

and my table was made correctly

(here is my SQLite connection class)

    package travelling_Ticket;

    import java.sql.*;

    import javax.swing.*;

    public class sqliteConnection {
        Connection conn = null;
        public static Connection dbConnector(){

            try {
                Class.forName("org.sqlite.JDBC");
                Connection conn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\cjt1496\\sqlite\\flightTimes.db");
                return conn;
            }catch ( Exception e ) {
                 JOptionPane.showMessageDialog(null, e);
              }
              System.out.println("Opened database successfully");
              return null;
           }

        }

(Here is the button that is supposed to show the database table of the flight times inside of a Jtable and the error that shows after compiling is that the table flightTimes cannot be found)

    JButton btnLoadFlights = new JButton("Load Flight Times");
            btnLoadFlights.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    try {
                        String query = "select * from flightTimes";
                        PreparedStatement pst = connection.prepareStatement(query);
                        ResultSet rs = pst.executeQuery();

                        table.setModel(DbUtils.resultSetToTableModel(rs));


                    }catch (Exception e1){
                        e1.printStackTrace();
                    }

                }
            });
5
  • So, "Opened database successfully" is printed as it is expected?
    – Geshode
    Oct 1, 2018 at 2:17
  • yes it printed as expected @Geshode Oct 1, 2018 at 2:36
  • If that message is displayed the database didn't get opened, though. You should change the message to one that's not misleading.
    – Shawn
    Oct 1, 2018 at 2:44
  • ok so put a JOptionPane inside the "try" and it printed successfully Oct 1, 2018 at 2:47
  • and deleted the other print Oct 1, 2018 at 2:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.