1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] IntelliJ Java SQLException (table not found) even if table is there

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I am studying java and have started learning about database implementation. I have decided to use SQLite and have already downloaded the .jav file, placed it in the classpath and used it in command prompt to create a database with two tables: dept and students. When I try to run some simple code in java I always get an SQLException saying the students table does not exist despite it defiitely being there. I have checked the path and the tables many times but just can't see the issue. If I don't fix this I will not be able to continue learning JDBC so it is very important. Here is the code:

    import java.sql.*;

    public class Main {
    public static void main(String[] args) {
    try {
    Class.forName("org.sqlite.JDBC");
    Connection conn = DriverManager.getConnection("jdbc:sqlite:C://sqlite//univ");

    Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery("select * from students");
    while (rs.next()) {
    System.out.print(rs.getInt("rollno") + " ");
    System.out.print(rs.getString("name") + " ");
    System.out.print(rs.getString("city") + " ");
    System.out.print(rs.getInt("deptno") + " ");
    }
    stmt.close();
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    }
    }


    This is the Error:

    org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such table: students)
    at org.sqlite.core.DB.newSQLException(DB.java:1179)
    at org.sqlite.core.DB.newSQLException(DB.java:1190)
    at org.sqlite.core.DB.throwex(DB.java:1150)
    at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
    at org.sqlite.core.NativeDB.prepare(NativeDB.java:135)
    at org.sqlite.core.DB.prepare(DB.java:264)
    at org.sqlite.jdbc3.JDBC3Statement.lambda$executeQuery$1(JDBC3Statement.java:87)
    at org.sqlite.jdbc3.JDBC3Statement.withConnectionTimeout(JDBC3Statement.java:458)
    at org.sqlite.jdbc3.JDBC3Statement.executeQuery(JDBC3Statement.java:85)
    at Main.main(Main.java:13)


    Any help would be greatly appreciated.

    Continue reading...

Compartilhe esta Página