【发布时间】:2019-10-26 12:19:10
【问题描述】:
我尝试为artikelID 获取destination(zielort),我将从我的GUI 中获取。不幸的是,我总是收到错误消息
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 未知列 'where 子句'中的'id'
在我的数据库中有一个 ID=1234 的 ArtikelID。在我的测试类中,我尝试获取ArtikelID 1234 的destination(zielort)。结果,我应该得到E1.R10.D2,,但我收到了错误消息。
希望你能帮我找出我的错误。
**Test Class:**
public static void main(String[] args) {
// TODO Auto-generated method stub
//DBConnect connect = new DBConnect();
//String s = connect.getLoginDaten(1);
//System.out.print(s);
DBConnect connect = new DBConnect();
String s= connect.getZielort(1234);
System.out.print(s);
}
**DB-Connect Class:**
public String getZielort(int arikel_ID) {
String zielort="";
try {
String query = "select zielort from warenliste where id="+arikel_ID;
rs= st.executeQuery(query);
while (rs.next()) {
zielort = rs.getString("zielort");
}
}
catch(Exception e) {
System.out.println(e);
}
return zielort;
}
public int getArtikel(int arikel_ID) {
int artikelid=0;
try {
String query = "select Artikel_ID from warenliste where id="+arikel_ID;
rs= st.executeQuery(query);
while (rs.next()) {
artikelid = rs.getInt("Artikel_ID");
}
}
catch(Exception e) {
System.out.println(e);
}
return artikelid;
}
【问题讨论】: