Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL error or missing database (near "AUTOINCREMENT": syntax error)

I am trying to Create 2 tables in SQLite Database. I am using sqlite-jdbc-3.32.3.2. but getting [SQLITE_ERROR] SQL error or missing database (near "AUTOINCREMENT": syntax error)

package logic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class SqliteComm{

    public static void main(String[] args) {
        initializeDatabase();
    }
    
    public static boolean initializeDatabase()
    {
        Connection connection = null;
        try {
            
            connection = DriverManager.getConnection("jdbc:sqlite:FamiilyTree.db");
            Statement statement = connection.createStatement();
            statement.executeUpdate("CREATE TABLE IF NOT EXISTS Person(person_id INTEGER AUTOINCREMENT PRIMARY KEY  , first_name text, middle_name text, last_name text, maternal_surname, gender text, description text, satus text)");
            statement.executeUpdate("CREATE TABLE IF NOT EXISTS Address(address_id INTEGER AUTOINCREMENT, type text");
            
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
        finally {  
            try {  
                if (connection != null) {  
                    connection.close();  
                }  
            } catch (SQLException ex) {  
                System.out.println(ex.getMessage());  
            }  
        }
        return true;
        
    }

}

I want to use Autoincrement for my Primary key while creating the table but getting [SQLITE_ERROR] SQL error or missing database (near "AUTOINCREMENT": syntax error)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

AUTOINCREMENT can go only after INTEGER PRIMARY KEY. Not in the middle, not alone.

INTEGER PRIMARY KEY AUTOINCREMENT
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading