目前,我正在使用IntelliJ IDEA,当我编写用于创建表的代码时,文本以黄色突出显示,当我查看问题时,我看到以下消息:
“没有配置数据源来运行此sql并提供高级代码帮助.通过问题菜单(⌥⏎)禁用此检查.”
我尝试更改sql方言(因为之前还有出现的消息)没有结果.
我该怎么办?我在代码中写错了但我不知道为什么其他的例子完美无缺.
这是代码:
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数据库,并建立了一个有效的连接(在此之前),如果它有用,这里是代码.
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());
}
}
}
所以…如果你能帮助我,我将不胜感激.
在此先感谢您的回答,祝您度过愉快的一天!
解决方法:
此警告表示您尚未在Intellij Idea中的数据库工具窗口中配置数据源.这并不意味着您的代码是错误的,它只是表明您没有基于数据库架构的代码完成.
在这里描述了Intellij中数据源的配置https://www.jetbrains.com/help/idea/2016.3/database-tool-window.html