Topic: JSP连接SQL2000问题 |
Print this page |
1.JSP连接SQL2000问题 | Copy to clipboard |
Posted by: bishan Posted on: 2006-05-07 15:54 装完JDK,TOMCAT以后我已经按照步骤连接了SQL2000,但用这个程序测试: <%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %> <html> <body> <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"; //pubs 为你的数据库的 String user="sa"; String password="admin"; Connection conn= DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select job_id,job_desc from jobs"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) { %> 您的第一个字段内容为:<%=rs.getString(1)%><br> 您的第二个字段内容为:<%=rs.getString(2)%><br> <% } %> <% out.print("数据库操作成功,恭喜你"); %> <% rs.close(); stmt.close(); conn.close(); %> </body> </html> 将上面的JSP代码保存为sql_test.jsp,放在/Root目录下。 在地址中输入:http://localhost:8080/sql_test.jsp 但测试结果却是: <£¥@¡¡page¡¡import="java.lang.*,¡¡java.io.*,¡¡java.sql.*,¡¡java.util.*"¡¡contentType="text/html;charset=gb2312"¡¡£¥> ¡¡¡¡ ¡¡¡¡ ¡¡¡¡<£¥¡¡Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); ¡¡¡¡¡¡String¡¡url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"; ¡¡¡¡¡¡//pubs¡¡ÎªÄãµÄÊý¾Ý¿âµÄ ¡¡¡¡¡¡String¡¡user="sa"; ¡¡¡¡¡¡String¡¡password="admin"; ¡¡¡¡¡¡Connection¡¡conn=¡¡DriverManager.getConnection(url,user,password); ¡¡¡¡¡¡Statement¡¡stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ¡¡¡¡¡¡String¡¡sql="select¡¡job_id,job_desc¡¡from¡¡jobs"; ¡¡¡¡¡¡ResultSet¡¡rs=stmt.executeQuery(sql); ¡¡¡¡¡¡while(rs.next())¡¡{¡¡£¥> ¡¡¡¡¡¡¡¡ÄúµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º<£¥=rs.getString(1)£¥> ¡¡¡¡¡¡¡¡ÄúµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º<£¥=rs.getString(2)£¥> ¡¡¡¡<£¥¡¡}¡¡£¥> ¡¡¡¡<£¥¡¡out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");¡¡£¥> ¡¡¡¡<£¥¡¡rs.close(); ¡¡¡¡¡¡stmt.close(); ¡¡¡¡¡¡conn.close(); ¡¡¡¡£¥> ¡¡¡¡ ¡¡¡¡ 所以请教高手帮我解决这个问题,看这种情况会是哪都出现了问题,谢谢! |
2.Re:JSP连接SQL2000问题 [Re: bishan] | Copy to clipboard |
Posted by: scottlai Posted on: 2006-05-07 17:51 % ? % ? |
3.Re:JSP连接SQL2000问题 [Re: bishan] | Copy to clipboard |
Posted by: why Posted on: 2006-05-07 19:09 是全形字符(包括空格)引致問題 |
4.Re:JSP连接SQL2000问题 [Re: bishan] | Copy to clipboard |
Posted by: bishan Posted on: 2006-05-07 22:26 按照大家的建议,我又检查了几遍测试程序,发现忘记改用户密码了,可改后用上面程序测试又出现了另外的错误: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 16 in the jsp file: /sql_test.jsp Generated servlet error: [javac] Compiling 1 source file D:\Tomcat\work\Standalone\localhost\_\sql_test_jsp.java:66: illegal character: \12288 ??rs.close(); ^ An error occurred at line: 16 in the jsp file: /sql_test.jsp Generated servlet error: D:\Tomcat\work\Standalone\localhost\_\sql_test_jsp.java:67: illegal character: \12288 ??stmt.close(); ^ An error occurred at line: 16 in the jsp file: /sql_test.jsp Generated servlet error: D:\Tomcat\work\Standalone\localhost\_\sql_test_jsp.java:68: illegal character: \12288 ??conn.close(); ^ An error occurred at line: 19 in the jsp file: /sql_test.jsp Generated servlet error: D:\Tomcat\work\Standalone\localhost\_\sql_test_jsp.java:69: illegal character: \12288 ???? ^ An error occurred at line: 19 in the jsp file: /sql_test.jsp Generated servlet error: D:\Tomcat\work\Standalone\localhost\_\sql_test_jsp.java:69: illegal character: \12288 ???? ^ 5 errors at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:248) at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:315) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:328) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:427) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:142) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534) 我是个新手,有好多问题都不懂,望大家多多帮忙,谢谢大家!!! -------------------------------------------------------------------------------- |
5.Re:JSP连接SQL2000问题 [Re: bishan] | Copy to clipboard |
Posted by: K_P_exciting Posted on: 2006-05-19 21:25 三楼的朋友都已经说明白了!!!你的%应该是在中文下输入的!! |
6.Re:JSP连接SQL2000问题 [Re: bishan] | Copy to clipboard |
Posted by: bishan Posted on: 2006-05-22 17:51 谢谢大家给予帮助。共同讨论,共同进步!!! |
7.Re:JSP连接SQL2000问题 [Re: bishan] | Copy to clipboard |
Posted by: heartache Posted on: 2006-06-02 21:36 可以用BAT文件转码的,我刚学会的 命令是 native2ascii 自己写的中文文件名字 要转换的文件名字 自己写的中文文件名字 这个里头一定要是自己写的中文,然后就运行BAT,发现你的 要转换的文件名字 这个文件里头代码转换了你不认识的/3/23/23//342/45%/什么的,那就恭喜你了 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |