执行Sql语句报出错误:'.' 附近有语法错误。求解答,急!!!!
有一段sql,Stringsql="selectdbo.Student.stuName,dbo.Employee.empId,dbo.Course.courseName,...
有一段sql,
String sql = "select dbo.Student.stuName, dbo.Employee.empId, dbo.Course.courseName, " +
"dbo.CourseClassStudent.stuId, dbo.Class.className" +
"from dbo.Student, dbo.Employee, dbo.Course, dbo.CourseClassStudent, dbo.Class, dbo.CourseClass" +
"where dbo.CourseClassStudent.courseClassId = dbo.CourseClass.courseClassId and " +
"dbo.CourseClass.empID = dbo.Employee.empId and " +
"dbo.Course.courseId = dbo.CourseClass.courseID and " +
"dbo.Student.classId = dbo.Class.classId and " +
"dbo.CourseClassStudent.stuId = dbo.Student.stuId and" +
"dbo.Employee.empId='" + empId + "'";
这句是执行sql的语句:ResultSet rs = db.(sql);
方法exeQuery:
public ResultSet exeQuery(String sql) {
getConnection();
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
控制台上显示是ResultSet rs = db.(sql);这句报错,'.' 附近有语法错误。
我跟踪了这个方法,发现是方法exeQuery中的rs = st.executeQuery(sql);这句报错。
但是我之前编代码运行其他sql的时候是没有错的,是不是我sql写的不对。。。。大家帮帮忙吧!!! 展开
String sql = "select dbo.Student.stuName, dbo.Employee.empId, dbo.Course.courseName, " +
"dbo.CourseClassStudent.stuId, dbo.Class.className" +
"from dbo.Student, dbo.Employee, dbo.Course, dbo.CourseClassStudent, dbo.Class, dbo.CourseClass" +
"where dbo.CourseClassStudent.courseClassId = dbo.CourseClass.courseClassId and " +
"dbo.CourseClass.empID = dbo.Employee.empId and " +
"dbo.Course.courseId = dbo.CourseClass.courseID and " +
"dbo.Student.classId = dbo.Class.classId and " +
"dbo.CourseClassStudent.stuId = dbo.Student.stuId and" +
"dbo.Employee.empId='" + empId + "'";
这句是执行sql的语句:ResultSet rs = db.(sql);
方法exeQuery:
public ResultSet exeQuery(String sql) {
getConnection();
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
控制台上显示是ResultSet rs = db.(sql);这句报错,'.' 附近有语法错误。
我跟踪了这个方法,发现是方法exeQuery中的rs = st.executeQuery(sql);这句报错。
但是我之前编代码运行其他sql的时候是没有错的,是不是我sql写的不对。。。。大家帮帮忙吧!!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询