Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want store into database but it thrown this error "
[SQLITE_ERROR] SQL error or missing database (no such table: githublists)
"

I already create this database and I check spelling is correct but still thrown this error.

What should I do to solve this ?

What I have tried:

package com;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class git {
   public static void main (String args[]) {
       final String url = "https://github.com/STIW3054-A202/Main-Data/issues/1";


       try {
           final Document document = Jsoup.connect(url).get();
           for (Element row : document.select("div.edit-comment-hide tr").subList(1, 29)) {
               if (row.select("[href]").text().equals("")) {
                   continue;
               } else {
                   final String githubID = row.select("[href]").text();
                   final String matricNo = row.select("p").text();
                   final String repository2 = matricNo.replace("Matic", "Matric");
                   final String matric = repository2.replace(" ", "");

                   git t = new git();
                   t.add(matric, githubID);
               }
           }
       } catch (IOException e) {
           e.printStackTrace();
       }
   }
       private Connection connect() {
           // SQLite connection string
           String url = "jdbc:sqlite:C://sqlite/db/test.db";
           Connection conn = null;
           try {
               conn = DriverManager.getConnection(url);
           } catch (SQLException e) {
               System.out.println(e.getMessage());
           }
           return conn;
       }
       public void add (String matric,String githubID ) {
           String sql = "INSERT INTO githublists(matric_no,githublinks) VALUES(?,?)";

           try (Connection conn = this.connect();
                PreparedStatement pstmt = conn.prepareStatement(sql)) {
               pstmt.setString(1, matric);
               pstmt.setString(2, githubID);
               pstmt.executeUpdate();
           } catch (SQLException e) {
               System.out.println(e.getMessage());
           }
       }

   }
Posted
Updated 18-Apr-21 20:40pm
Comments
Richard MacCutchan 19-Apr-21 3:28am    
I have just created a database with the correct table and column names and run your code, and it works fine. Your issue must be connected to the file you are using.

1 solution

The error message is pretty much self explanatory:
[SQLITE_ERROR] SQL error or missing database (no such table: githublists)
It's telling you as clearly as it can that you have asked it to INSERT data into a table called "githublists" and that table does not exist in that file.
Check your SqLite database file - make sure it's the one listed in the connection string - and pay attention to the table names: did you call it "githublist" or "githublists" for example.

And don't "hard code" connection strings into you app - always use a config file as otherwise you have to release untested software once you change the location for release versions.
 
Share this answer
 
Comments
Cow cow Lee 19-Apr-21 2:57am    
I have check this sqlite database file and the name is the same exactly I call.So I do know went wrong.
OriginalGriff 19-Apr-21 3:27am    
Which db file did you access, and how did you access it? When did you access it? From which computer?

Remember, I have no access to your file system!
Cow cow Lee 19-Apr-21 8:02am    
Thank advice, using same computer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900