lz用的是sqlserver2008的话,驱动classname为:com.microsoft.sqlserver.jdbc.SQLServerDriver
08和以前的版本驱动包名发生了一点变化,具体你可以看你的驱动jar,打开看到包名其实是com.microsoft.sqlserver.jdbc还有url为:jdbc:sqlserver://localhost:1433;DatabaseName=friend

解决方案 »

  1.   

    提示说找不到驱动类,你把你的包打开看看,有没有com.microsoft.jdbc.sqlserver.SQLServerDriver这个类,如果没有,你换一个你的驱动包下的驱动类试试
      

  2.   

    我使用的是sql2005,而且包里面有这个类,我写过一个测试类测试连接都可以,却在这里就找不到..
      

  3.   

    给你个完整的吧package com.accp.testring.dao.impl;import java.sql.*;public class BaseDao {
    private static final String URL ="jdbc:sqlserver://localhost:1433;databaseName=friend";
    private static final String CLASSNAME="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private static final String UNAME="sa";
    private static final String UPASS="sa";


    /**
     * 得到数据库连接通道
     * @return conn
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public Connection getConn() throws ClassNotFoundException, SQLException{
    Class.forName(CLASSNAME);
    Connection conn = DriverManager.getConnection(URL,UNAME,UPASS);
    return conn;
    }

    /**
     * 执行增、删除、修改,不能执行查询
     * @param preparedSQL
     * @param param
     * @return 受影响行数
     */
    public int executeSQL(String preparedSQL,Object[] param){
    int num = 0;
    Connection conn = null;
    PreparedStatement pres = null;
    /* 处理SQL,执行SQL*/
    try {
    conn = getConn();
    pres = conn.prepareStatement(preparedSQL);
    if(param != null){
    for(int i=0;i<param.length;i++){
    pres.setObject(i+1, param[i]);
    }
    }
    num = pres.executeUpdate();   //执行sql语句
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }catch(SQLException sqle){
    sqle.printStackTrace();
    }finally{
    closeAll(conn,pres,null);
    }
    return num;
    }

    /**
     * 释放资源
     * @param con
     * @param pstmt
     * @param rs
     */
    public void closeAll(Connection con,PreparedStatement pstmt,ResultSet rs){
    /*如果rs不空,关闭rs*/
    if(rs !=null){
    try {
    rs.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    /*如果pstmt不空,关闭pstmt*/
    if(pstmt!=null){
    try {
    pstmt.close();
    }catch (SQLException e) {
    e.printStackTrace();
    }
    }
    /*如果con不空,关闭con*/
    if(con !=null){
    try {
    con.close();
    }catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }
    public ResultSet getProc(String proc,Object[] params){
    Connection conn = null;
    PreparedStatement cstm= null;
    ResultSet rs =null;
    try {
    conn=this.getConn();
    }catch(Exception e){
    e.printStackTrace();
    }
    try{
    cstm=conn.prepareCall(proc);
    if(params!=null){
    for(int i=0;i<params.length;i++){
    cstm.setObject(i+1, params[i]);
    }
    }
    rs=cstm.executeQuery();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return rs;
    }
    }