我得到的錯誤:MySQL的例外 - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
'Unknown column 'customerno' in 'field list' '.
但是,在我的客戶表中存在的列。那爲什麼我會得到這個異常?
代碼:
import java.sql.*;
public class Classy {
static String myQuery =
"SELECT customerno, name" +
"FROM customers;";
public static void main(String[]args)
{
String username = "cowboy";
String password = "1234567";
try
{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Business", username, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(myQuery);
while(rs.next())
{
System.out.print(rs.getString("customerno"));
}
} catch(SQLException ex){System.out.println(ex);}
}
}
感謝,而不是添加一個空格!我不知道這種事情不會由API本身處理。 – 2012-07-21 17:28:14
@sweetdreams:它怎麼可能?你剛剛得到了一個*字符串* - 如何知道當你寫「nameFROM」時,你的意思是「name FROM」?這是要求一點點的API ... – 2012-07-21 21:54:21
是啊...我的笨:( – 2012-07-21 22:01:47