注册 登录
编程论坛 J2EE论坛

JSP连接数据库问题 急!急!急!

光光 发布于 2006-04-09 23:59, 1177 次点击

路径配置
.;C:\j2sdk1.5.0\lib\tools.jar;C:\j2sdk1.5.0\lib\dt.jar;D:\java;C:\j2sdk1.5.0\jre\bin\rt.jar;.;D:\jsptest\Tomcat 5.0\common\lib\servlet.jar;.C:\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar

出错信息:
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /sqltest.jsp(1,4) Invalid directive
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:83)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:402)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:548)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1625)
org.apache.jasper.compiler.Parser.parse(Parser.java:173)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:247)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:149)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:135)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:243)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.12

测试程序
<%@ 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=mydatabase";
   //pubs 为你的数据库的
   String user="sa";
   String password="";
   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>

数据库3个文件被粘到:D:\jsptest\Tomcat 5.0\common\lib

SP3补丁也按完了
请各位大侠帮忙看看

15 回复
#2
疯子java2006-04-10 09:43

在你的第一行使用了很多的中文空格

#3
piaoxue2006-04-10 11:55
空格用中文的也不行吗? 应该可以吧,只要符号是英文状态下就可以吧!  学习中....
#4
bimnm2006-04-10 16:19
String password="";/*??????????
是你没设密码
还是 装SQL的时候用的 不是"混合登录"
如果 装SQL的时候用的 是windows 登录 把它改成
混合登录 就好了*/
#5
光光2006-04-10 17:19
怎么改成混合登陆啊,在程序上,请具体一点
#6
dreame2006-04-10 19:02

企业管理器中可以新建登陆的!!

#7
光光2006-04-11 00:20
我没有设密码,也从微软网站上下了JDBC 驱动程序 SQL Server 2000 Driver for JDBC SP3
但是SP3补丁不是从微软网站上下的,不知道行不行
#8
疯子java2006-04-11 09:11

我认为大家讨论的是不是有点过了哟
看每看错误日志呀
错误明明说的jsp的第一行有错误的嘛
大家干嘛要扯到数据库上去呀

#9
光光2006-04-11 18:11
第一行是有中文空格,但是改了之后还是有这样子的错误:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673)
	org.apache.jsp.sqltest_jsp._jspService(sqltest_jsp.java:78)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
	com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
	com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
	com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
	com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)
	com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
	com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
	com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
	com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
	java.sql.DriverManager.getConnection(Unknown Source)
	java.sql.DriverManager.getConnection(Unknown Source)
	org.apache.jsp.sqltest_jsp._jspService(sqltest_jsp.java:52)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat logs.


Apache Tomcat/5.0.12

#10
光光2006-04-13 11:35
怎么测试URL呢???
#11
miss_friend2006-04-13 13:28

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
这个错在网上一搜有好多呢,主要是你的jdbc驱运有问题下sp3,看看你的系统防火墙是不是默认关闭1433端口,以及你的驱动是不是放在了,web-inf中lib下面等等,自己试试说不定就好了

#12
光光2006-04-13 15:26
驱动要放在了,web-inf中lib下面吗,那3个文件不是要放在common\lib下面吗
SP3补丁我已经下完拉
#13
光光2006-04-13 15:28
D:\jsptest\Tomcat 5.0\webapps\ROOT\WEB-INF下吗
#14
光光2006-04-13 15:31
D:\jsptest\Tomcat 5.0\common\lib
放这里是对的把,我觉得
#15
bagger2006-04-13 16:57
../Tomcat 5.0\common\lib
是正确的
#16
lqb152006-04-16 10:06
我也是同样的问题,急啊!
1