Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No data sources are configured to run this SQL

I have a little problem with the creation of a table (for a database) in Java.

Currently, I'm using IntelliJ IDEA and when I write the code for creating a table the text is highlighted in yellow and when I look to the problem I see the following message:

"No data sources are configured to run this SQL and provide advanced code assistance. Disable this inspection via problem menu (⌥⏎)."

I tried with changing the SQL dialect (because before there was also that message that appeared) without result.

What should I do? I wrote something wrong in the code but I don't know why whit other example work perfectly.

Here's 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've already create a SQLite database and established a connection that works (before that), here's the code if it could be useful.

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... If you can help me I would be grateful.

Thanks in advance for the answer and have a nice day!

like image 681
Ingialldus Avatar asked Mar 21 '17 16:03

Ingialldus


People also ask

Where is the Data Source in IntelliJ?

To access the Data Sources and Drivers dialog ( Shift+Enter ), perform one of the following actions: In the Database tool window (View | Tool Windows | Database), click the Data Source Properties button. . In the Database tool window (View | Tool Windows | Database), click the Add button.

How do you add a Data Source?

Create a new data sourceIn the Connect to data tab, select the type of data you to which you want to connect. Select the specific data set and provide your authorization, if necessary. In the bottom right, click Add.


1 Answers

The message:

No data sources are configured to run this SQL and provide advanced code assistance.`

is a little explicit and IMHO a little unnecessary, because I really think that I don't need to configure a database for every project in which we have some SQL queries.

To handle this message, you have two options:

  1. Configure a Data Source to your project, using the ALT + ENTER above the message and using the option Configure a Data Source: Add a data source

or

  1. Disable this SQL dialect detection inspection on the Inspection options on the IDE settings:

Disable the SQL dialect detection

You may need to disable as well No data sources configured inspection on:

Inspections -> SQL -> No data sources configured

The second option is the best approach for me unless you really want or need a Data Source in your project.

like image 64
valdeci Avatar answered Sep 23 '22 14:09

valdeci