当前位置: 代码迷 >> Java Web开发 >> 我用JSP往SQLServer中导入数据怎么不能成功啊?请教大家!
  详细解决方案

我用JSP往SQLServer中导入数据怎么不能成功啊?请教大家!

热度:221   发布时间:2006-05-17 10:46:00.0
我用JSP往SQLServer中导入数据怎么不能成功啊?请教大家!

下面是往数据库中插入数据的代码,红色部分是因为 我装SQLServer的时候,用的是WINDOWS验证
听朋友说这是使用SQLServer的常见错误,但都不知道该怎么解决,请大家帮忙,谢谢了!!
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.io.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

</head>

<body>
<center>
往数据库中添加数据:<hr>
<%
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev","Administrator","19810229");
PreparedStatement pstmt=con.prepareStatement("insert into contact values(?,?,?,?,?,?)");

pstmt.setString(1,"王小华");
pstmt.setInt(2,1383820);
pstmt.setString(3,"010455554");
pstmt.setString(4,"lala@eyou.com");
pstmt.setDate(5,new java.sql.Date(new java.util.Date().getTime()));
pstmt.setString(6,"很久没有联系了");
pstmt.execute();

pstmt.close();

Statement stmt=con.createStatement();
stmt.execute("insert into contact(userName,mobile) values ('陈军',1340255)");
out.println("添加数据成功");

stmt.close();
con.close();

}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>
显示下面的错误:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at org.apache.jsp.DB.query_jsp._jspService(query_jsp.java:102)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
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:595)

搜索更多相关主题的帖子: SQLServer  JSP  数据  

----------------解决方案--------------------------------------------------------

这个确实是mssql的常见错误,不过出现问题的地方还是很不好确定
比如,mssql没有启动,jdbc没有,好像有防火墙有时候也有问题的
呵呵,还有一些情况我也不知道了,你自己好好查一下


----------------解决方案--------------------------------------------------------

我是菜鸟,我怎么会查呢?往哪查都不知道啊
不过首先我的SQLServer启动了,安装了JDBC 放火墙关了


----------------解决方案--------------------------------------------------------
看一下
http://www.javaresearch.org/faq/thread.jsp?column=723&thread=25705
----------------解决方案--------------------------------------------------------
http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=123&threadID=33122&tstart=0

还有一个
我以前都一直没有遇到这样的问题
我希望遇到问题的时候
大家先自己检查和查资料解决,实在不行再大家讨论
----------------解决方案--------------------------------------------------------
不行的,我都看了,都一步步的做了,还是不行  不知道怎么回事,我的确不明白
----------------解决方案--------------------------------------------------------

你MSSQLServer2000是用混合登陆模式安装的吗?
似乎只有混合登陆模式才能登陆~~
还有把JDBC和SQLServer全升级到SP3版
1、下载Microsoft SQL Server 2000 Service Pack 3a并安装,SQL请选用混和安装模式!!!
http://www.microsoft.com/downloads/details.aspx?FamilyId=90DCD52C-0488-4E46-AFBF-ACACE5369FA3&displaylang=zh-cn

2、下载SQL Server 2000 Driver for JDBC Service Pack 3
http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en

3、运行时关闭防火墙
我原来也碰到过和你一样的问题~~做完这3步应该问题就可以解决了~~


----------------解决方案--------------------------------------------------------

谢谢楼上的各位大哥,在郁闷了3天,反复安装,卸载了3天之后,题终于解决
原因:我的SP4不知道在哪下载的,有问题,换了个SP4就好了

在这里提醒一下大家,SP4不但要打,也要打上正确的版本
还有楼上的 疯子java 和 xhdwell 说的 综合以下肯定能成


----------------解决方案--------------------------------------------------------
  相关解决方案