jsp连接sqlserver数据库的问题

lanyuefang 2004-09-09 04:31:37
jsp文件如下:
<%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
  String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
  //pubs为你的数据库的
  String user="sa";
  String password="111";
  
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from ddd";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  您的第一个字段内容为:<%=rs.getString(1)%>
  您的第二个字段内容为:<%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜你");%>
  <%rs.close();
  stmt.close();
  conn.close();
  
  %>
  </body>
  </html>
运行报错:
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:47: illegal character: \12288
[javac] ????String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:47: illegal character: \12288
[javac] ????String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:48: illegal character: \12288
[javac] ????//pubs涓轰?????????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:48: illegal character: \12288
[javac] ????//pubs涓轰?????????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:49: illegal character: \12288
[javac] ????String user="sa";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:49: illegal character: \12288
[javac] ????String user="sa";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:50: illegal character: \12288
[javac] ????String password="111";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:50: illegal character: \12288
[javac] ????String password="111";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:51: illegal character: \12288
[javac] ????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:51: illegal character: \12288
[javac] ????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:52: illegal character: \12288
[javac] ????Connection conn= DriverManager.getConnection(url,user,password);
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:52: illegal character: \12288
[javac] ????Connection conn= DriverManager.getConnection(url,user,password);
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:53: illegal character: \12288
[javac] ????Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:53: illegal character: \12288
[javac] ????Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:54: illegal character: \12288
[javac] ????String sql="select * from ddd";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:54: illegal character: \12288
[javac] ????String sql="select * from ddd";
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:55: illegal character: \12288
[javac] ????ResultSet rs=stmt.executeQuery(sql);
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:55: illegal character: \12288
[javac] ????ResultSet rs=stmt.executeQuery(sql);
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:56: illegal character: \12288
[javac] ????while(rs.next()) {
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:56: illegal character: \12288
[javac] ????while(rs.next()) {
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:67: illegal character: \12288
[javac] ????stmt.close();
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:67: illegal character: \12288
[javac] ????stmt.close();
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:68: illegal character: \12288
[javac] ????conn.close();
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:68: illegal character: \12288
[javac] ????conn.close();
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:69: illegal character: \12288
[javac] ????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:69: illegal character: \12288
[javac] ????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:70: illegal character: \12288
[javac] ????
[javac] ^
[javac] D:\Tomcat 4.1\work\Standalone\localhost\examples\test_jsp.java:70: illegal character: \12288
[javac] ????
[javac] ^
[javac] 28 errors
望解决

...全文
547 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Net8Java 2004-09-09
恩,头有点昏~!
回复
power17 2004-09-09
另外请楼主还是注意一下,写代码要规范一点,方便自己维护,也能让别人一目了然。
回复
power17 2004-09-09
我没有改什么。只是字符上出了点问题。以后要是出现了找个好一点的编辑器就可以解决了。

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
String user="sa";
String password="lll";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from ddd";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功!");%>
<%
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

这段代码没有问题的
我已经调试过了。
回复
52800195 2004-09-09
看看这个吧~!
<%
java.sql.Connection conn;
java.sql.Statement stmt;
java.sql.ResultSet rs;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tao";
String user="sa";
String password="";
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

%>

回复
airli2309 2004-09-09
localhost:1433,好像是这里错了!
回复
xiangbo520 2004-09-09
第一,你必须安装SQL SERVER 2000的补丁,现在已经出来了SP3,使用JAVA连接SQL SERVER 2000,前提是必须安装SP3;
谁说要装补丁的,我以前没装补丁就用的好好的。
回复
happycj 2004-09-09
空格问题???????????/
回复
yxxcrtd 2004-09-09
第一,你必须安装SQL SERVER 2000的补丁,现在已经出来了SP3,使用JAVA连接SQL SERVER 2000,前提是必须安装SP3;
第二,安装JDBC驱动后,应该在环境变量里设置好三个JAR文件:mssqlserver.jar,msutil.jar,msbase.jar
设置环境变量后,建议重新启动机器.然后就可以进行实际连接动作了,建议先用JAVA来连接,不要用JSP(有些情况下,JSP给出的错误提示比较难搞)
回复
tiger362573 2004-09-09
把注释那句删掉。象一些冒号、单引号、双引号等字符要重新在英文输入法状态下输入,用中文输入法输入或直接在网页上考下来就会出错!
回复
skyboy0720 2004-09-09
代码一些考过来字符的问题!你先拷贝到记事本里,然后再拷贝到文件里!
相必你是直接从网上拷贝到文件里吧!
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-09 04:31
社区公告
暂无公告