请大家帮我指点下错误的信息,谢谢
package datepaseConnect;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Select {
public static void main(String[] args) {
Connection conn=null;
Statement stm =null;
ResultSet res=null;
try {
//获取数据库连接
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("数据库驱动加载成功");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=BDQN_1";
String username="sa";
String password="qaz123";
conn=DriverManager.getConnection(url, username, password);
System.out.println("数据库连接成功");
//建立数据库通道
stm=conn.createStatement();
//声明要执行的sql语句
String sql="SELECT KC.kechengcode,KC.kechengname,KC.kechengcontent,CL.classname " +
"FROM kecheng AS KC INNER JOIN classinfo AS CL" +
"ON CL.classid=KC.classid ";
//获取查询结果集
res=stm.executeQuery(sql);
//使用while循环遍历结果集
while(res.next()){
System.out.print(res.getString("kechengcode"));
System.out.print(res.getString("kechengname"));
System.out.println(res.getString("kechengcontent"));
System.out.println(res.getString("classname"));
}
} catch (Exception e) {
e.printStackTrace();
}
try {
res.close();
stm.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
报告的异常信息:
数据库驱动加载成功
数据库连接成功
com.microsoft.sqlserver.jdbc.SQLServerException: 'CL' 附近有语法错误。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:616)
at datepaseConnect.Select.main(Select.java:31)
java.lang.NullPointerException
at datepaseConnect.Select.main(Select.java:48)
}
}