如何跟msslq数据库连接?

zhaohh 2004-05-03 02:37:29
各位大虾,请问jsp中如何跟msslq数据库连接,请求详细代码?
我用的是jbuild9.0+Tomcat 4.1+mssql server 2000
...全文
44 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lhbf 2004-05-03
同意 sagittarius1979(射手爱狮子)
不过,你要把那三个文件放在yourapp\WEB-INF\lib下
  • 打赏
  • 举报
回复
zhaohh 2004-05-03
sagittarius1979(射手爱狮子) ( )
我用你的程序出先了以下错误,不知道是什么原因:
type Exception report

message

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

exception

org.apache.jasper.JasperException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.ceshi_jsp._jspService(ceshi_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)

  • 打赏
  • 举报
回复
zhaohh 2004-05-03
我试一下!成功马上结帖!
  • 打赏
  • 举报
回复
sagittarius1979 2004-05-03
import java.sql.* ;
import javax.sql.*;


("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs";
String user="sa";
String password="123456";
Connection conn= DriverManager.getConnection(url,user,password);
  • 打赏
  • 举报
回复
alan520cf 2004-05-03
我把原代码给你
改一下jdbc那里就可以了
// Java Document
import java.sql.*;
public class sql_data
{
String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
//String ConnStr="jdbc:odbc:ClassDB,sa,sa";
Connection conn=null;
ResultSet rs=null;
//String id,password;
public sql_data()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("sql_data():"+e.getMessage());
}
}
public void Insert(String sql)
{
try{
conn=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
catch(SQLException ex)
{
System.err.println("sql_data.Insert:"+ex.getMessage());
}
}
public void Update(String sql)
{
try{
conn=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
catch(SQLException ex)
{
System.err.println("sql_data.Update:"+ex.getMessage());
}
}
public ResultSet Query(String sql)
{
rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
Statement stmt=conn.createStatement();
stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.Query:"+ex.getMessage());
}
return rs;
}
public void Delete(String sql)
{
try{
conn=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
catch(SQLException ex)
{
System.err.println("sql_data.Delete:"+ex.getMessage());
}
}
public void Disconnection()
{
try{
if(conn!=null) conn.close();
if(rs!=null) rs.close();
}
catch(Exception ex)
{
System.err.println("sql_data.Disconnection:"+ex.getMessage());
}
}
}
  • 打赏
  • 举报
回复
zhaohh 2004-05-03
怎么都没人回答
!自己up一下!
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
加入

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-05-03 02:37
社区公告
暂无公告