0

I try to add a new data into SQLite Database. The connection is established successfully, however, when I add new data, nothing is shown in the DB table. Can anyone help me to solve this problem? Thank you

package database;

import java.sql.*;

public class Database {

public static void main(String[] args) {
    // TODO code application logic here
    Connection c = null;
    try {
        Class.forName("org.sqlite.JDBC");
        c = DriverManager.getConnection("jdbc:sqlite:admin.db");
        System.out.println("Connection is established");

        String SQLadd = "insert into" + "admins(user_name,password)" + "values('sachin', 'kafle')";
        Statement stmt = c.createStatement();
        stmt.executeUpdate(SQLadd);
        //c.commit();
        //c.close();
    }
    catch (Exception e) {
        System.out.println("Can not connect to database");
        //System.exit(0);
    }
}

}
4
  • 1
    You're missing a space between into and admins in your query String. Also, you shouldn't swallow the Exception like that (at least print the stack trace). Commented Mar 26, 2019 at 4:56
  • Are you getting any error? The SQL statement might not be correct. also check if you need to flush/close any connections/streams. Commented Mar 26, 2019 at 4:57
  • I dont get any error. I saw this code on a online course video so I just write the same with the video's code. However, nothing's shown in DB table no matter my code have nothing different with the code in video Commented Mar 26, 2019 at 5:00
  • I did miss the space between "into" and "admins". Thanks for helping Commented Mar 26, 2019 at 5:09

1 Answer 1

1

I think you should give space between into and admins, also after values, or just do like following :

String SQLadd = "insert into admins(user_name,password) values('sachin', 'kafle')";     

Hope it helps... :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.