| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 979 人关注过本帖
标题:我用JSP往SQLServer中导入数据怎么不能成功啊?请教大家!
取消只看楼主 加入收藏
小猪笨笨
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-4-19
收藏
 问题点数:0 回复次数:3 
我用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 数据 
2006-05-17 10:46
小猪笨笨
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-4-19
收藏
得分:0 

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


A flea in the JAVA
2006-05-17 11:48
小猪笨笨
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-4-19
收藏
得分:0 
不行的,我都看了,都一步步的做了,还是不行  不知道怎么回事,我的确不明白

A flea in the JAVA
2006-05-17 18:25
小猪笨笨
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-4-19
收藏
得分:0 

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

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


A flea in the JAVA
2006-05-19 09:30
快速回复:我用JSP往SQLServer中导入数据怎么不能成功啊?请教大家!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.068575 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved