-1

I have try to connect SQLite database to jtable using java swing.

import java.sql.*;
public class Database {

    public static void main(String[] args) throws Exception {
        // Get the path to the encrypted database file.
        String databaseFile = "DataBase/demo.db?cipher=SQLiteCipher&password=demo&key=demo";
        
        // Create a connection to the encrypted database file.

        Connection connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile);
        System.out.println("Connected");

        // Create a statement object and use it to execute queries against the database.
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM demo");

        // Iterate over the results and print them to the console.
        while (resultSet.next()) {
            System.out.println(resultSet.getString("ItemName"));
        }

//         Close all of the open resources.
        resultSet.close();
        statement.close();
        connection.close();
    }
}

I want to connect the sqlite3 database to jtable.

Aravind S
  • 1
  • 1
  • If your question is how to create the table then you need to add the data to a TableModel. Check out: https://stackoverflow.com/a/55635012/131872 – camickr Aug 23 '23 at 14:30
  • no i wanted to connect these database by decrpyting the password using java – Aravind S Aug 24 '23 at 04:43
  • So then why does your question mention a JTable? That is irrelevant. Keep the question simple so we now exactly what the problem is that you are trying to solve. – camickr Aug 24 '23 at 13:18
  • after connected with database i wanted to populate the jtable with this database table. – Aravind S Aug 25 '23 at 04:14
  • What you want to da after connecting to the database is irrelevant to your stated problem. Your problem is connecting to the database, Twice you mentioned JTable, so it seems your problem is loading the data into the JTable which is confusing. In any case I know nothing about your stated problem and you have been given a solution for populating the JTable after you solve your problem. – camickr Aug 25 '23 at 13:29

0 Answers0