Java – no data source is configured to run this SQL

I have a problem creating tables (for databases) in Java

At present, I am using IntelliJ idea. When I write code to create a table, the text is highlighted in yellow. When I look at the problem, I see the following message:

"The data source is not configured to run this SQL and provide advanced code help. Disable this check through the problems menu (⌥⏎)."

I tried to change the SQL dialect (because there were messages before) and there was no result

What should I do? I made a mistake in the code, but I don't know why the other examples are perfect

This is the code:

public static void createTable(){

    //connect to database
    String url = percorsoDatabase;

    //Statement create new table
    String sql = "CREATE TABLE IF NOT EXISTS Tabella (id PRIMARY KEY," +
            "video TEXT," +
            "game TEXT," +
            "firstAction TEXT," +
            "secondAction TEXT," +
            "thirdAction TEXT);";

    try {
        Connection conn = DriverManager.getConnection(url);
        Statement stmt = conn.createStatement();
        stmt.execute(sql);
    } catch (sqlException e ){
            System.out.println(e.getMessage());
    }

}

I have created a SQLite database and established a valid connection (before that). If it is useful, here is the code

public static void main(String[] args) {

    createNewDatabase();
    connection();
    createTable();
}

public static void createNewDatabase(){

    String url = percorsoDatabase;

    Connection conn;
    try {

     conn = DriverManager.getConnection(url);
        if (conn != null){
            DatabaseMetaData Meta = conn.getMetaData();
            System.out.println("The driver name is" + Meta.getDriverName());
            System.out.println("A new database has been created.");
        }
    } catch (sqlException e){
        System.out.println(e.getMessage());
    }

}

public static void connection(){

    Connection conn = null;
    try {
        //String url = "jdbc:sqlite://Volumes/Isma/Documenti/SUPSI/APA/Stage/"
        //        + "Beans/esperimento/dati.db";
        conn = DriverManager.getConnection(percorsoDatabase);
        System.out.println("Connection to sqlite established.");
    } catch (sqlException e){
        System.out.println(e.getMessage());
    } finally {
        try {
            if (conn != null){
                conn.close();
            }
        } catch (sqlException e){
            System.out.println(e.getMessage());
        }
    }

}

So... I would appreciate it if you could help me

Thank you for your reply and have a nice day!

Solution

This warning indicates that you have not configured a data source in the database tools window in IntelliJ idea This does not mean that your code is wrong, it just means that you have not completed the code based on database architecture

The configuration of data sources in IntelliJ is described here https://www.jetbrains.com/help/idea/2016.3/database-tool-window.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>