0

I have a program connecting to DB but when I call the table it says the tables does not exist. I have deleted table and remade it a few times. I am using the sqlite manager plugin for firefox, there is a sqlite_master table. When I select that table it does not give me any errors...

I think it has to do with it adding main when I create the table and add data to it.

is it adding main as a prefix?

INSERT INTO "main"."contacts" ("Business_Name","First_Name","Last_Name","Phone","Email","Address_Line_1","Address_Line_2","Website") VALUES (?1,?2,?3,?4,?5,?6,?7,?8)
Parameters:
param 1 (text): Texcom
param 2 (text): Jesse
param 3 (text): Lovelace
param 4 (text): 817-555-9999
param 5 (text): [email protected]
param 6 (text): 852 hemming way
param 7 (text): Colleyville, TX 76034
param 8 (text): www.texcom.com

Anyone have any ideas here?

import javax.swing.*;
import java.sql.*;

public class DbConnect {

    Connection conn = null;
    public static Connection ConnectDb() {

        try{
            Class.forName("org.sqlite.JDBC");
            Connection conn = DriverManager.getConnection("jdbc:sqlite:systemDb.Documents\\workspace\\DiazProject4\\addressBook.sqlite");
            JOptionPane.showMessageDialog(null, "DB Connected");        
                    return conn;
        }catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
            return null;
        }
        }
    }


import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.*;

import java.sql.*;

import net.proteanit.sql.DbUtils;

public class Driver {

    private JFrame f;

    private JPanel p;

    private JTextField fieldBN;
    private JTextField fieldFN;
    private JTextField fieldLN;
    private JTextField fieldP;
    private JTextField fieldE;
    private JTextField fieldA;
    private JTextField aLine2;
    private JTextField fieldW;

    private JLabel labelBN;
    private JLabel labelFN;
    private JLabel labelLN;
    private JLabel labelP;
    private JLabel labelE;
    private JLabel labelA;
    private JLabel labelW;

    private JButton buttonS;

    private JTable tableDisplay;

    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    // Constructor:

    public Driver() {       
        gui();      
        conn = DbConnect.ConnectDb();
        UpdateTable();
    }

    public void gui() { 
        f = new JFrame("Contact Book");


        GridBagConstraints c = new GridBagConstraints();  

        c.insets = new Insets(10, 10, 10, 10);

        p = new JPanel(new GridBagLayout());
        f.getContentPane().add(p, BorderLayout.NORTH);

    c.gridx = 0;
    c.gridy = 0;
    labelBN = new JLabel ("Business Name:");
    p.add(labelBN, c);  

    c.gridx = 10;
    c.gridy = 0;
    fieldBN = new JTextField(10);
    p.add(fieldBN, c);

    c.gridx = 0;
    c.gridy = 10;
    labelFN= new JLabel ("First Name:");
    p.add(labelFN, c);      

    c.gridx = 10;
    c.gridy = 10;
    fieldFN = new JTextField (10);
    p.add(fieldFN, c);

    c.gridx = 0;
    c.gridy = 20;
    labelLN= new JLabel ("Last Name:");
    p.add(labelLN, c);      

    c.gridx = 10;
    c.gridy = 20;
    fieldLN = new JTextField (10);
    p.add(fieldLN, c);

    c.gridx = 0;
    c.gridy = 30;
    labelP = new JLabel ("Phone Number:");
    p.add(labelP, c);

    c.gridx = 10;
    c.gridy = 30;
    fieldP = new JTextField (10);
    p.add(fieldP, c);

    c.gridx = 0;
    c.gridy = 40;
    labelE = new JLabel ("Email:");
    p.add(labelE, c);

    c.gridx = 10;
    c.gridy = 40;
    fieldE = new JTextField (10);
    p.add(fieldE, c);

    c.gridx = 0;
    c.gridy = 50;                           
    labelA = new JLabel ("Address:");
    p.add(labelA, c);

    c.gridx = 10;
    c.gridy = 50;
    fieldA = new JTextField (10);
    p.add(fieldA, c);
    c.gridx = 10;
    c.gridy = 60;
    aLine2 = new JTextField (10);
    p.add(aLine2, c);

    c.gridx = 0;
    c.gridy = 70;
    labelW = new JLabel ("Website:");
    p.add(labelW, c);

    c.gridx = 10;
    c.gridy = 70;
    fieldW = new JTextField (10);
    p.add(fieldW, c);

    c.gridx = 10;
    c.gridy = 80;
    buttonS = new JButton("Save:");
    p.add(buttonS, c);

    c.gridx = 10;
    c.gridy = 90;
    tableDisplay = new JTable(8, 2);
    p.add(tableDisplay, c);

        // pack the frame for better cross platform support
        f.pack();
        // Make it visible
        f.setVisible(true);
        f.setSize(500,800); // default size is 0,0
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } // End of Gui Method

    private void UpdateTable() {
        try {
        String sql = "SELECT * FROM entries";
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        tableDisplay.setModel(DbUtils.resultSetToTableModel(rs));
    }

    catch(Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
           public void run() {
                new Driver();

           }
        });
    } // End main Method

       } // End class Driver
6
  • Please check your connection string, try to use a full path: "jdbc:sqlite:C:\\your\\path\\to\\your\\db" Commented Mar 14, 2014 at 16:23
  • im on a mac. no C. and it says im connected so I know the path is correct. I think maybe the problem is here, I think by default its adding main when I create the table sand entries you see? INSERT INTO "main"."contacts" ("Business_Name","First_Name","Last_Name","Phone","Email","Address_Line_1","Address_Line_2","Website") VALUES (?1,?2,?3,?4,?5,?6,?7,?8) Parameters: param 1 (text): Texcom param 2 (text): Jesse param 3 (text): Lovelace param 4 (text): 817-555-9999 param 5 (text): [email protected] param 6 (text): 852 hemming way param 7 (text): Colleyville, TX 76034 Commented Mar 14, 2014 at 16:26
  • Oops I see..If you use the 'main' prefix, remove the double quotes and use square brackets somethig like this: INSERT INTO [main].contacts .... right now I can't test, but I believe that you could skip the whole "main" prefix. Commented Mar 14, 2014 at 18:13
  • well the plugin is adding that. and when I removed it it didnt help... Commented Mar 14, 2014 at 18:17
  • omg... so the problem was my path was wrong. My DB was in the root of my program so I did not have to start the path from the beginning... I just need to start in root... make an answer telling me to check the path and I will accept it. thanks for your help. Commented Mar 14, 2014 at 18:47

1 Answer 1

1

Please check your connection string, check the full path:

DriverManager.getConnection("jdbc:sqlite:YOUR_DATABASE_PATH");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.