Ingialldus
Ingialldus

Reputation: 377

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!

Upvotes: 36

Views: 72267

Answers (5)

valdeci
valdeci

Reputation: 15237

The message:

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

is a little explicit and, in my opinion, somewhat unnecessary, because I don't think we need to configure a database for every project that has some SQL queries.

To handle this message, you have two options:

  1. Configure a Data Source for your project by using ALT + ENTER above the message and selecting the option Configure a Data Source:

    Add a data source

  2. Disable the SQL dialect detection inspection in the IDE settings:

    Disable the SQL dialect detection

    You may also need to disable the No data sources configured inspection at: 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.

Upvotes: 48

jccbc
jccbc

Reputation: 1

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

Upvotes: 0

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

Upvotes: 4

Tomasz Jagiełło
Tomasz Jagiełło

Reputation: 854

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

Upvotes: 19

olizimmermann
olizimmermann

Reputation: 82

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?

Upvotes: -1

Related Questions