没有配置数据源来运行此SQL [英] No data sources are configured to run this SQL

查看:5205
本文介绍了没有配置数据源来运行此SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Java创建表(对于数据库)时遇到了一些问题。

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

目前,我正在使用IntelliJ IDEA,当我编写用于创建表格的代码,文本以黄色突出显示,当我查看问题时,我看到以下消息:

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:

没有数据源配置为运行这个SQL并提供高级代码帮助。通过问题菜单(⌥⏎)禁用此检查。

我尝试更改SQL方言(因为之前那里)也是那个没有结果的消息。

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

我该怎么办?我在代码中写错了但我不知道为什么whit其他示例工作得很好。

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

这是代码:

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());
    }

}

我已经创建了一个SQLite数据库并建立了一个有效的连接(在此之前),这是代码,如果它可能有用。

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!

推荐答案

此警告表示您尚未在Intellij Idea的数据库工具窗口中配置数据源。这并不意味着您的代码是错误的,它只是表明您没有基于数据库架构的代码完成。

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.

描述了Intellij中数据源的配置 https://www.jetbrains.com/help/idea /2016.3/database-tool-window.html

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

这篇关于没有配置数据源来运行此SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆