日期:2014-05-18  浏览次数:20618 次

求助JDBC连接问题,谢谢啊.
请各位高手帮忙看看以下程序,在连接数据库时出错(sqlserver服务器已打开并存在jspdev数据库;sqlserver三个驱动程序已经加载到shop工程目录下的lib下;在D:\apache-tomcat-5.5.12\common\lib下也存在此驱动程序),源程序和错误提示如下:
谢谢!

package   shop;
import   java.sql.*;

public   class   DBConnectBean   {
    public   static   Connection   getSqlserverConn()
    {
      Connection   conn=null;
      String   url= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
      String   sqldriver= "jdbc:microsoft:sqlserver://localhost:1433 ";
    try   {
        Class.forName(url);
        conn=DriverManager.getConnection(sqldriver, "sa ", " ");
        conn.setCatalog( "jspdev ");
    }
    catch   (Exception   ex)   {
        ex.printStackTrace();

    }
        return   conn;
    }
}


package   shop;
import   java.sql.*;

public   class   SqlserverInit   {
  public   static   void   createTable()
  {
        Connection   con=null;
    try   {
        con=DBConnectBean.getSqlserverConn();
        Statement   stmt   =   con.createStatement();
        stmt.execute( "create   table   type(type_id   int   primary   key,type_name   varchar(50)) ");
        stmt.execute( "create   table   product(prod_id   int   primary   key,prod_name   varchar(50),price   float,type   int) ");
con.close();
    }
    catch   (SQLException   ex)   {
        ex.printStackTrace();
    }
  }
  public   static   void   insertData()
  {
    Connection   con=null;
    try{
        con=DBConnectBean.getSqlserverConn();
        Statement   stmt=con.createStatement();
        con.setAutoCommit(false);
            stmt.addBatch( "insert   into   type   values(100, '玉器系列 ') ");
            stmt.addBatch( "insert   into   type   values(200, '雕塑系列 ') ");
            stmt.addBatch( "insert   into   product   values(10001, '涴雄 ',100,100) ");
            stmt.addBatch( "insert   into   product   values(10002, '鹿 ',100,100) ");
            stmt.addBatch( "insert   into   product   values(10003, '领头羊 ',100,100) ");
            stmt.addBatch( "insert   into   product   values(10004, '熊猫 ',100,200) ");
            stmt.addBatch( "insert   into   product   values(10005, '勇攀高峰 ',100,200) ");
  &n