gpt4 book ai didi

java - MySQL版本错误

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

我有以下错误:

**Average of Job_Render  is 138.29047 and its Minimum value is : 2.00061 and Maximum value is :7499.75
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select avg(kdt_build_Box_Gen), max(kdt_build_Box_Gen),min(kdt_build_Box_Gen) fro' at line 1
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select avg(kdt_build_Box_Gen), max(kdt_build_Box_Gen),min(kdt_build_Box_Gen) fro' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2949)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:959)
at com.journaldev.json.AggregateSum.main(AggregateSum.java:70)******

这是代码:

private static final String DB_DRIVER = "com.mysql.jdbc.Driver";
private static final String DB_CONNECTION = "jdbc:mysql://localhost:3306/";
private static final String DB_USER = "root";
private static final String DB_PASSWORD = "root";
private static final String dbName = "raas";

public static final String[] COLUMNS = {"Job_Render","kdt_build_Box_Gen", "Adaptation_Luminance","LightMan_finalize_PA","IES_bytes","GeomMan_finalize_Total","KDTree_Kickstart","Indirect_Tree_Build","Average_Cutsize","cube_map_count","GeomMan_finalize_accel_build","Direct_Tree_Build","Direct_VPL_Sampling","Scene_Setup_Total","Direct_VPL_Filtering","File_cache_hit_rate","Downloaded_bytes"};

public static void main(String[] args) throws ClassNotFoundException,SQLException {


try {
Connection conn = null;
Statement stmt = null;

// STEP 2: Register JDBC driver
Class.forName(DB_DRIVER);

// STEP 3: Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_CONNECTION + dbName, DB_USER,
DB_PASSWORD);
System.out.println("Connected database successfully...");


stmt = conn.createStatement();
String sql1 = "select * from ras;";


String sql = "";
for (int idx = 0; idx < COLUMNS.length; ++idx) {
String F = COLUMNS[idx];
sql += "select avg("+F+"), max("+ F +"),min("+ F+") from ras;";


boolean isMoreRecordsAvailable = false;
ResultSet rs = stmt.executeQuery(sql);
isMoreRecordsAvailable = rs.next();

while (isMoreRecordsAvailable) {
System.out.println("Average of " + F + " is "
+ rs.getFloat(1) + " and its Minimum value is : "
+ rs.getFloat(3) + " and Maximum value is :"
+ rs.getFloat(2));

isMoreRecordsAvailable = rs.next();
}




}





} catch (Exception e) {

System.out.println(e);
System.out.println("There it is");
e.printStackTrace();
}
}
}

我什至尝试检查报价是否正确。我不知道为什么我会收到此错误。我想对 String[] 列中初始化的所有字段运行循环;但它只执行Job_Render,但它抛出异常。

最佳答案

它执行异常是因为您多次连接 SELECT 和 FROM。您需要删除加号:

String sql = "select avg("+F+"), max("+ F +"),min("+ F+") from ras;";

并从 for 循环外部删除 String sql 定义。

关于java - MySQL版本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25147841/

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