I keep getting the following error when running my code: java.sql.SQLException: Column 'Hours Worked' not found.
Any ideas on where I'm going wrong, I apologize if it is obvious, I'm still trying to learn how to properly use JDBC.
Here is where i think the error is in my code:
String sql = "SELECT jobID, 'Hours'+'/'+'Worked', Description, Address, 'Materials'+'/'+'Used', Seen FROM main";
ResultSet rs = stmt.executeQuery(sql);
//Extract data from result set
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("JobID");
int Hrs = rs.getInt("Hours Worked");
String description = rs.getString("Description");
String Address = rs.getString("Address");
String Materials = rs.getString("Materials Used");
String Seen = rs.getString("Seen");
//Display values
System.out.print("JobID: " + id);
System.out.print(", Hours Worked: " + Hrs);
System.out.print(", Description: " + description);
System.out.println(", Address: " + Address);
System.out.println(", Materials Used: " + Materials);
System.out.println(", Seen: " + Seen);
}
在SQL Server查询中,您必须在方括号中用空格将列名称包裹起来,如下所示:
String sql = "SELECT jobID, [Hours Worked], Description, Address, [Materials Used], Seen FROM main";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.