27

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!

Ingialldus
  • 287
  • 1
  • 4
  • 7

5 Answers5

36

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.

valdeci
  • 13,962
  • 6
  • 55
  • 80
20

This warning indicates that you have not configured data source in Database Tool Window in Intellij Idea. It doesn't mean that your code is wrong, it just shows that you don't have code completion based on your database schema.

Configuration of datasource in Intellij is described here https://www.jetbrains.com/help/idea/database-tool-window.html

5

The IntelliJ Idea is an intelligent IDE, and sometimes need some configurations that can help you soon.

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

The above-mentioned warning will never affect your application and you can easily skip it, but by setting the data source you can take advantage of IntelliJ's Database tools and SQL outstanding features.

To set the data-source follow View Tools Window Database and then click the Data Source Properties button. In the shown window select your database and fill in the required text fields.

The demonstration of steps are shown in the following GIF:

enter image description here

Elyas Hadizadeh
  • 3,289
  • 8
  • 40
  • 54
0

I think you should check the connection to your database.

url - a database url of the form jdbc:subprotocol:subname

Check the Api https://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html#getConnection(java.lang.String)

Did you add the ODBC correct?

olizimmermann
  • 74
  • 1
  • 2
  • 9
0

I disable the no data sources configured, and I set a ignore option, no warning shows up. setting -> Inspections -> no data sources configured -> +

pycharm setting

jccbc
  • 1
  • 1