首次使用jdbc,很多不懂,请教大家,我从microsoft上下载了sqlserver的jdbc,测试代码如下
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=booksms";
//pubs 为你的数据库的
String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from message";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) 
{ 
%>
  您的第一个字段内容为:<%=rs.getString(1)%><br>
  您的第二个字段内容为:<%=rs.getString(2)%><br>
<% } %>
<% out.print("数据库操作成功,恭喜你"); %>
<% rs.close();
stmt.close();
conn.close();这个是网上搜索来的最多的测试代码
但是一直都不成功
错误如下::/book/sql.jsp:5: illegal character: \12288
      \u3000
           ^
/book/sql.jsp:7: illegal character: \12288
String\u3000url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=booksms";
           ^
/book/sql.jsp:7: not a statement
String\u3000url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=booksms";
^
/book/sql.jsp:9: illegal character: \12288
String\u3000user="sa";
           ^
/book/sql.jsp:9: not a statement
String\u3000user="sa";
^
/book/sql.jsp:10: illegal character: \12288
String\u3000password="sa";
           ^
/book/sql.jsp:10: not a statement
String\u3000password="sa";
^
/book/sql.jsp:11: illegal character: \12288
Connection\u3000conn=\u3000DriverManager.getConnection(url,user,password);
               ^
/book/sql.jsp:11: not a statement
Connection\u3000conn=\u3000DriverManager.getConnection(url,user,password);
^
/book/sql.jsp:11: illegal character: \12288
Connection\u3000conn=\u3000DriverManager.getConnection(url,user,password);
                          ^
/book/sql.jsp:12: illegal character: \12288
Statement\u3000stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
              ^
/book/sql.jsp:12: not a statement
Statement\u3000stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
^
/book/sql.jsp:13: illegal character: \12288
String\u3000sql="select * from\u3000message";
           ^
/book/sql.jsp:13: not a statement
String\u3000sql="select * from\u3000message";
^
/book/sql.jsp:14: illegal character: \12288
ResultSet\u3000rs=stmt.executeQuery(sql);
              ^
/book/sql.jsp:14: not a statement
ResultSet\u3000rs=stmt.executeQuery(sql);
^
/book/sql.jsp:15: illegal character: \12288
while(rs.next())\u3000{\u3000
                     ^
/book/sql.jsp:15: illegal character: \12288
while(rs.next())\u3000{\u3000
                            ^
/book/sql.jsp:18: illegal character: \12288
      \u3000}\u3000
           ^
/book/sql.jsp:18: illegal character: \12288
      \u3000}\u3000
                  ^
/book/sql.jsp:19: illegal character: \12288
      \u3000out.print("\u6570\u636e\u5e93\u64cd\u4f5c\u6210\u529f\uff0c\u606d\u559c\u4f60");\u3000
           ^
/book/sql.jsp:19: illegal character: \12288
      \u3000out.print("\u6570\u636e\u5e93\u64cd\u4f5c\u6210\u529f\uff0c\u606d\u559c\u4f60");\u3000
                                                                                                 ^
/book/sql.jsp:20: illegal character: \12288
      \u3000rs.close();
           ^
/book/sql.jsp:15: cannot resolve symbol
symbol  : variable rs 
location: class _jsp._book._sql__jsp
while(rs.next())\u3000{\u3000
      ^
/book/sql.jsp:21: cannot resolve symbol
symbol  : variable stmt 
location: class _jsp._book._sql__jsp
stmt.close();
^
/book/sql.jsp:22: cannot resolve symbol
symbol  : variable conn 
location: class _jsp._book._sql__jsp
conn.close();
^
26 errors

解决方案 »

  1.   

    哪位仁兄帮忙解决下,什么地方出了问题
      

  2.   

    自己重新写一遍吧
    一大堆乱七八糟的字符
      

  3.   

    很明显是中文空格引起的问题
    从网上直接复制下来是不行的
    要将中文空可和符号删掉
      

  4.   

    复制粘贴的话。楼主是很难把他学好的。。要自己巧。。一个一个仔细的。反复的巧
      

  5.   

    肯定里面有中文字符,你的把:和//重新打一下
      

  6.   

    你把代码放在记事本里.然后再从记事本里放到编辑器里.应该就可以了.