When I try to insert values into my H2 Table it says table not found, even though the table exists What could be wrong?

时间:2017-03-02 23:28:37

标签: java database netbeans h2

I am using Netbeans to make a POS system and I am trying to insert values into an H2 table.The database connection seems to function properly and the table exists but I keep getting the table not found error. Here is my code to make the connection

package h2finalproj;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Connor Hicks
 */
public class HDBConnect {
    public static Connection connDB()
    {           

        try {
            Class.forName("org.h2.Driver");
            Connection   conn=DriverManager.getConnection("jdbc:h2:~\\cghicks1 [   database];","cghicks1","");

             return conn;
         } catch (ClassNotFoundException | SQLException e) {
             JOptionPane.showMessageDialog(null, e);
         }
        return null;
    }
 }
 public class H2FinalProj extends javax.swing.JFrame {
 Connection connect = null;
 ResultSet rst=null;
 PreparedStatement pst=null;
 PreparedStatement crt = null;


 public H2FinalProj() {
        initComponents();
        connect = HDBConnect.connDB(); 
    }

Here is my code to insert values:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)           
    try {
             String sql;

             sql = "INSERT INTO \"PUBLIC\".INVENTORY (PRODNUM, PRODNAME, PRICE, STOCK) values(?,?,?,?)";

        pst = connect.prepareStatement(sql);
        pst.setString(1, prodNum2.getText());
        pst.setString(2,prodName2.getText());
        pst.setString(3, price2.getText());
        pst.setString(4, numStock2.getText());
        pst.execute();

        JOptionPane.showMessageDialog(null, "Success !");
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, e);
    }
}   

And the error I am receiving looks something like this:

SQL Exception Table "Inventory not found" [42102-190]

I have found somewhat similar questions and solutions but nothing that seems to be close or clear enough to solve this problem.

This question has a problem description which is extremely similar to mine however both my application and console are already using 1.4, so the solution does not seem to help me.

Embedded h2 database: getting connection but table not found

How might I solve this?

0 个答案:

没有答案