gpt4 book ai didi

java - 无法弄清楚如何消除 mysql 上的语法错误

转载 作者:行者123 更新时间:2023-11-29 16:06:11 25 4
gpt4 key购买 nike

我正在尝试在 java 主文件上运行语句,并且能够连接到数据库,但无法运行 sql 语句我的代码是:

try {
System.out.println("Connecting to the database...");
conn=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Connected to database successfully");
System.out.println("Inserting");
stmt=conn.createStatement();
String sql="USE TheEmployeeDatabase" +
"SELECT * FROM EmployeeTable";
stmt.executeUpdate(sql);
System.out.println("worked");
} catch (SQLException e) {
e.printStackTrace();
}

并收到错误

You have an error in your SQL syntax

最佳答案

只要架构名称 TheEmployeeDatabase1DB_URL 的一部分,您就不需要使用 USE TheEmployeeDatabase 语句。

你的声明应该是:

SELECT * FROM EmployeeTable

关于java - 无法弄清楚如何消除 mysql 上的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55717133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com