在过去的6-7个小时里,我一直在搜索/谷歌搜索/试验解决方案,但到目前为止没有结果。
我有一个SQL字符串(下面),它在PHPMYADMIN中完美地工作,但在我的java执行中不起作用。在尝试执行查询时,我得到“列摆脱未找到。”
的SQLException:
java.sql.SQLException: Column 'rid' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1167)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2851)
at net.matthewauld.racetrack.server.WrSQL.getJSONClassSpecificRiders(WrSQL.java:41)
at net.matthewauld.racetrack.server.ClientListener.parseCommand(ClientListener.java:110)
at net.matthewauld.racetrack.server.ClientListener.run(ClientListener.java:42)
-
SELECT * FROM `riders` WHERE EXISTS(SELECT * FROM `ridersclasses` WHERE ridersclasses.rid = riders.id AND `cid` = '6') ORDER BY `first_name` ASC
这是我执行SQL查询的java代码。
url = "jdbc:mysql://127.0.0.1:3306/racetrack2013?allowMultiQueries=true";
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery(query);
下面我将发布两个表的结构和一些数据示例:
RidersClasses
+---------------------------------------------------+
| ridersclasses |
+---------------------------------------------------+
| ID | RID | CID | BIKENUMBER | BIKEMODEL |
+---------------------------------------------------+
骑手
+----------------------------------------------------------------------------------+
| Riders |
+----------------------------------------------------------------------------------+
| ID | first_name | last_name | address | city_id | h_phone | c_phone |
+----------------------------------------------------------------------------------+
答案 0 :(得分:6)
问题很简单:rid
表中没有riders
列。
如图所示,问题始于getInt
而不是rs.getInt("rid")
使用rs.getInt("id")