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)

>Solution :

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

INTEGER PRIMARY KEY AUTOINCREMENT

Leave a Reply