是否把sqlserver2000的驱动拷贝到了lib目录下?

解决方案 »

  1.   

    相关jar都加入到了lib下了,
    <code>
    package com.cityinfo.dao;import java.sql.*;public class Test
    {
    public static void main(String[] args)
    {
    String DriverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";  //定义数据库的驱动
    String DBurl =  "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=db_CityInfo"; //定义数据库连接
    Connection conn = null; //声明数据库连接
    Statement stmt = null; 
    ResultSet rs = null;
    String user = "sa";
    String password = "sa";

    try
    {
    Class.forName(DriverName);
    conn = DriverManager.getConnection(DBurl,user,password);
    stmt = conn.createStatement();
    rs = stmt.executeQuery("select * from tb_info");
    while(rs.next())
    {
    System.out.println(rs.getString("name"));
    }
    }
    catch(ClassNotFoundException e)
    {
    e.printStackTrace();  //将exception写入log4j的日志文件中
    }
    catch(SQLException e)
    {
    e.printStackTrace();
    }
    finally
    {
    try
    {
    if(rs != null)
    {
    rs.close();
    rs= null;
    }
    if(stmt !=null)
    {
    stmt.close();
    stmt=null;
    }
    if(conn != null)
    {
    conn.close();
    conn=null;
    }
    }
    catch(SQLException e)
    {
    e.printStackTrace();
    }
    }
    }
    }
    </code>
      

  2.   

    cmd---> netstat -a 
    看看1433端口开了没?