我在JSP中用JDBC连接SQLSERVER2000,用的开发工具是Eclipse,jdk 5.0 ,tomcat 5.0,JDBC连接用的驱动3个包都已经导入,方法和程序如下 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
   Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jsp","sa","1");
   Statement stmt=con.createStatement();
    ResultSet rst=stmt.executeQuery("select * from book;");
出现的错误是HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.test_jsp._jspService(test_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
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.<init>(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(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.test_jsp._jspService(test_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
大家看是什么问题

解决方案 »

  1.   

    前一句改为:
     Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
      

  2.   

    搬凳子坐下好好学习中...
    -------------------------------------------------------------------------
    您好,网美书店全场5折-8.8折,深圳东莞所有地区送书上门(免配送费),书到付款!网美书店网址:http://www.wanme.com
      

  3.   

    连接SQL  的软件我装了阿,我的系统是sp2,不过这跟系统补丁防火墙好像没什么关系吧
    这句话我也改过了Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    还是这个错误
    还有人帮忙吗
      

  4.   

    楼主真是牛
    都用到了JDK 5.0
    看来偶是在是太落后了。才用到1.4
      

  5.   

    如果是XP系统,把SQLSERVER打个SP3的补丁试试
      

  6.   

    /**
    *创建于2005.7.25
    *
    */
    /**
    *@author lijing
    *//** 这是wx_base_propertice 的 key list
    *@ConnectionDriver
    *@ConnectionUrl
    *@ConnectionUser
    *@ConnectionPassword
    *//** about Propertice.store()
    Throws: 
    IOException - if writing this property list to the specified output stream throws an IOException. 
    ClassCastException - if this Properties object contains any keys or values that are not Strings. 
    NullPointerException - if out is null.*/
    package com.lijing.classes;
    import java.util.Properties;
    //import java.io.InputStream;
    //import java.io.OutputStream;
    import java.io.*;
    import java.sql.*;public class PropertiesForWXBASE
    {
    /**
    */
    public static void IniProperticewxData()
    throws IOException
    {
    Properties props = new Properties();
    OutputStream out =  new FileOutputStream("wxbase_propertice");
    props.put("ConnectionDriver","com.microsoft.jdbc.sqlserver.SQLServerDriver");
    props.put("ConnectionUrl","jdbc:microsoft:sqlserver://server1:1433");
    props.put("ConnectionUser","sa");
    props.put("ConnectionPassword","111111");
    props.store(out,"----------------->");
    out.close();
    }
    /**在 properties 文件中 设置驱动
    *@param m_ConnectionDriver 是数据库的 驱动类型
    *@return no
    *@throws IOException,ClassCastException,NullPointerException
    */
    public void SetConnectionDriverwx(String m_ConnectionDriver)
    throws IOException,ClassCastException,NullPointerException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //设置 key of ConnectionDriver
    props.setProperty("ConnectionDriver",m_ConnectionDriver);
    OutputStream out =  new FileOutputStream("wxbase_propertice");
    props.store(out,"----------------->");
    out.close();
    in.close();
    }

    /**在 properties 文件中设置url
    *@param m_ConnectionUrl 连接的url,such as:
    *jdbc:microsoft:sqlserver://server1:1433;user=test;password=secret
    *@return no
    *@throws IOException,ClassCastException,NullPointerException
    */
    public void SetConnectionUrlwx(String m_ConnectionUrl)
    throws IOException,ClassCastException,NullPointerException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //设置 key of ConnectionUrl
    props.setProperty("ConnectionUrl",m_ConnectionUrl);
    OutputStream out =  new FileOutputStream("wxbase_propertice");
    props.store(out,"----------------->");
    out.close();
    in.close();
    }

    /**在 properties 文件中 设置用户
    *@param m_ConnectionUser 用户名称
    *@return no
    *@throws IOException,ClassCastException,NullPointerException
    */
    public void SetConnectionUserwx(String m_ConnectionUser)
    throws IOException,ClassCastException,NullPointerException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //设置 key of ConnectionUser
    props.setProperty("ConnectionUser",m_ConnectionUser);
    OutputStream out =  new FileOutputStream("wxbase_propertice");
    props.store(out,"----------------->");
    out.close();
    in.close();
    }

    /**在 properties 文件中设置 登陆 数据库的 密码 
    *@param m_ConnectionPassword 登陆 数据库 所用到的密码 
    *@return no
    *@throws IOException,ClassCastException,NullPointerException
    */
    public void SetConnectionPasswordwx(String m_ConnectionPassword)
    throws IOException,ClassCastException,NullPointerException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //设置 key of ConnectionPassword
    props.setProperty("ConnectionPassword",m_ConnectionPassword);
    OutputStream out =  new FileOutputStream("wxbase_propertice");
    props.store(out,"----------------->");
    out.close();
    in.close();
    }

    /**
     * 得到 connection
     * @return
     * @throws IOException
     */
    public Connection GetConnection()
    throws IOException
    {
    String ConnectionDriver,ConnectionUrl,ConnectionUser,ConnectionPassword;
    Connection con; ConnectionDriver = this.GetConnectionDriverwx();
    ConnectionUrl = this.GetConnectionUrlwx();
    ConnectionUser = this.GetConnectionUserwx();
    ConnectionPassword = this.GetConnectionPasswordwx();

    //装载 数据库 连接驱动
    try 
    {
    System.out.println(ConnectionDriver);
    Class.forName(ConnectionDriver); } 
    catch(java.lang.ClassNotFoundException e) 
    {
    System.err.print("ClassNotFoundException: "); 
    System.err.println(e.getMessage());
    }

    try
    {
    //连接
    con = DriverManager.getConnection(ConnectionUrl,ConnectionUser,ConnectionPassword);
    return con;
    }
    catch(SQLException ex) 
    {
    System.err.println("SQLException: " + ex.getMessage());
    return null;
    }

    }

    /**从 properties 文件中 读取 驱动 字符串
    *@return string ,驱动 字符串
    *@throws IOException
    */
    public String GetConnectionDriverwx()
    throws IOException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //读入 ConnectionDriver
    String str = props.getProperty("ConnectionDriver");
    in.close();
    return str;
    }

    /**从  properties 文件中 读取 DriverManager.getConnection()需要的内容
    *@return string  connecton url
    *@throws IOException
    */
    public String GetConnectionUrlwx()
    throws IOException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //读入 ConnectionUrl
    String str = props.getProperty("ConnectionUrl");
    in.close();
    return str;
    }

    /**从 properties 文件中 读 等入数据库的 帐号 
    *@return string  登入数据库的帐号 
    *@throws IOException
    */
    public String GetConnectionUserwx()
    throws IOException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //读入 ConnectionUser
    String str = props.getProperty("ConnectionUser");
    in.close();
    return str;
    }

    /**从 properties 文件中读 帐号的密码 
    *@return string 密码 
    *@throws IOException
    */
    public String GetConnectionPasswordwx()
    throws IOException
    {
    //读入原始的 设置
    Properties props = new Properties();
    InputStream in = new FileInputStream("wxbase_propertice");
    props.load(in);

    //读入 ConnectionPassword
    String str = props.getProperty("ConnectionPassword");
    in.close();
    return str;
    }
    }
      

  7.   

    从Properties里面读出字符串的值与直接赋值不是一回事吗,我不明白你加入了一个Properties是什么目的,还有你这个类里没有自己定义的构造函数阿,你是不是说要改public static void IniProperticewxData()
    这个函数吧,你说的方法我还没试过,等我试一试,如果成功了一定要好好理解一下你的做法
      

  8.   

    呵呵,其他的事设置,Properties 文件里属性的东西,然后再从文件里读属性,构造函数直接在文件里初始化属性public void DeleteInThisTable_lj(HttpServletRequest req)
    throws IOException
    {
    Connection con;

    // 得到 session ,并将数据 交给 session
    HttpSession m_session = req.getSession(true);
    String m_nsdmid=(String)m_session.getAttribute("NSDMID");
    String m_yearid=(String)m_session.getAttribute("YEARID");

    // this is the DeleteString
    String DeleteString;
    CStringMaker m_CStringMaker = new CStringMaker("T_SBSYCJB");
    m_CStringMaker.UpdateStringStepAdd("sign");
    m_CStringMaker.UpdateStringConAdd("CS_NSDM");
    m_CStringMaker.UpdateStringConAdd("CS_YEAR");
    DeleteString = m_CStringMaker.GetUpdateString();

    System.out.println(DeleteString);

    try 
    {
    //连接
    //con = DriverManager.getConnection(ConnectionUrl,ConnectionUser,ConnectionPassword);
    con = m_pro.GetConnection();

    con.setAutoCommit(false);
    PreparedStatement up_str = con.prepareStatement(DeleteString);
    up_str.setInt(1,1);
    up_str.setString(2,m_nsdmid);
    up_str.setString(3,m_yearid);

    up_str.executeUpdate();
    con.setAutoCommit(true);
    up_str.close();
    con.close();

    catch(SQLException ex) 
    {
    System.err.println("SQLException: " + ex.getMessage());
    }
    }比如这样使用,只用申明一个 PropertiesForWXBASE m_pro = new PropertiesForWXBASE();就可以了。主要是给你测试一下的,如果设置对,你的数据库可以连上,不过后来,我有3个帖子了,回复不了了。不过到今天才接上,估计已经没有什么意义了