想连接SQLSERVER7.0,用的是JTDS的驱动,也设了环境变量,仍然提示classnotfound,不知怎么回事,哪位达人能指点迷津.最好是从下驱动到设变量都有的,越详细越好,不胜感激~~~~

解决方案 »

  1.   

    /*
     * put your module comment here
     * formatted with JxBeauty (c) [email protected]
     */
    import  java.sql.*;
    /**
     * put your documentation comment here
     */
    public class Connect {    /**
         * put your documentation comment here
         * @param args
         * @exception Exception
         */
        public static void main (String[] args) throws Exception {
            String user = "sa";
            String pwd = "sa";
            String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;selectMethod=cursor";
            String drv = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
            try {
                Class.forName(drv).newInstance();
                Connection con = DriverManager.getConnection(url, user, pwd);
                Statement stmt = con.createStatement();
                String sql = "select * from jobs ";
                ResultSet result = stmt.executeQuery(sql);
                while (result.next()) {
                    System.out.print(result.getString(1));
                    System.out.print(result.getString(2));
                    System.out.print(result.getString(3));
                    System.out.println(result.getString(4));
                }
                stmt.close();
                con.close();
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }不行 换JSQLConnect驱动试试
      

  2.   

    一楼那位朋友的方法我试过,不行.可能我的环境变量什么的设的不对,能否将步骤说的详细些。我用的是JTDS的驱动,先下了个jtds-0.6.jar文件拷到JDK安装路径下的LIB目录下。在CALSSPATH里设置变量为JDK安装路径\lib\jtds-0.6.jar。但仍然提示classnotfound
      

  3.   

    需要
    Class.forName(drv).newInstance();吗?
    我一般只写:
    Class.forName(drv);就行了。
      

  4.   

    将安装驱动后产生的三个文件msbase.jar;mssqlserver.jar;msutil.jar
    放到C:\j2sdk1.4.2_05\jre\lib\ext目录下就可以编程了,不需要另外配置环境变量了!然后试着运行下面的代码!
     import java.sql.*;
     import java.io.*;
     import java.util.*;
     
     /**
     6.    This program tests that the database and the JDBC
     7.    driver are correctly configured.
     */
     class TestDB
     {
        public static void main (String args[])
        {
           try
           {
              runTest();
           }
           catch (SQLException ex)
           {
              while (ex != null)
              {
                 ex.printStackTrace();
                 ex = ex.getNextException();
             }
           }
           catch (IOException ex)
           {
              ex.printStackTrace();
           }
        }    /**
    32.       Runs a test by creating a table, adding a value, showing the table contents, and
    33.       removing the table.
    34.    */
        public static void runTest()
           throws SQLException, IOException
        {
           Connection conn = getConnection();
           try
           {
              Statement stat = conn.createStatement();          ResultSet result = stat.executeQuery("SELECT * FROM Mst_Company");
              while(result.next())
             {
              System.out.println(result.getString(1));
             }
           }
           finally
           {
              conn.close();
           }
        }    /**
           Gets a connection from the properties specified
           in the file database.properties
          @return the database connection
        */
        public static Connection getConnection()
           throws SQLException, IOException
        {
    try
    {
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
    }
    catch(Exception e)
    {
    System.out.println(e);
    }        String url ="jdbc:microsoft:sqlserver://192.168.1.24:1433;DatabaseName=marunaka";
           String username = "dbuser";
           String password = "qaz123";       return DriverManager.getConnection(url, username, password);
        }
     }修改一下,ip地址,数据库名,用户名,密码,sql语句,你就可以运行了!
      

  5.   

    请给个microsoft SQLServer7.0驱动下载的连接,谢谢!
      

  6.   

    不好意思,今天上午这里不能登录。邮箱是[email protected],谢谢!
      

  7.   

    没收到哎,:(再发一次,好吧?
    那个驱动有多大?小于1.5M的话,可发到[email protected]
      

  8.   

    下了一个I-NET的驱动,已经搞好了.谢谢各位!特别感谢圆缘:)