1

I recently started working on JDBC and I got an Error as Table not found

Table TRIAL not found; SQL statement:
insert into trial values(1,'hello') [42102-73]

Here is my code, also I have already created a table in h2 DB

package trial1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Customer {

    public static void main(String[] args) {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:h2:~/test","Aziz", "password");
            Statement st = conn.createStatement();
            String str = "insert into trial values(1,'hello')";
                    st.execute(str);
            System.out.println("Succes");
        }
        catch(Exception e) {
            e.printStackTrace();
        }

    }

}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mob_Abominator
  • 196
  • 2
  • 5
  • 19
  • 1
    As the error tells you, there is no table called `TRIAL` in your database. Make sure the table exists. – Mark Rotteveel Sep 22 '18 at 15:31
  • now i'm getting another error as : ava.sql.SQLException: No suitable driver found for dbc:h2:tcp://localhost/~/test at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:247) at trial1.Customer.main(Customer.java:12) – Mob_Abominator Sep 22 '18 at 15:44
  • 1
    Check https://stackoverflow.com/questions/5556664/how-to-fix-no-suitable-driver-found-for-jdbcmysql-localhost-dbname-error-w – Jahnavi Paliwal Sep 22 '18 at 15:47
  • 1
    That error in your comments is because your URL is wrong, it needs to start with `jdbc`, not with `dbc`. – Mark Rotteveel Sep 22 '18 at 16:19
  • Thankyou very much. So silly of me after correcting the spell the program worked for me. – Mob_Abominator Sep 23 '18 at 03:52

0 Answers0