jsp查询数据库错误

来源:百度知道 编辑:UC知道 时间:2024/06/17 17:06:40
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
;
String url= "jdbc:sqlserver://localhost:1433;DatabaseName=jsp;user=sa;password=123456";
Connection conn = DriverManager.getConnection(url);
Statement smt = conn.createStatement();

ResultSet rs = smt.executeQuery("select * from user");
while(rs.next()){
out.println(rs.getString(1));
out.print("database is open,ok!");
}
smt.close();
conn.close();
%>
运行错误com.microsoft.sqlserver.jdbc.SQLServerException: 关键字 'user' 附近有语法错误。
到底怎么错了

ResultSet rs = smt.executeQuery("select * from [user]");

user 是保留字,需要转义才能使用

你需要把jar解压看看实际的包和类是不是你写的这个顺序。com.microsoft.sqlserver.jdbc.SQLServerException
有不同版本的。有的是jdbc在sqlserver之前。

一般随jar都有帮助文档,你可以看看对这个版本中的相关说明。