没用过tomcat
不过应该和其它的差不多,你要有一个连数据库的driver
//取得一个driver
try {
Class.forName(你的driver).newInstance();
} catch (Exception e) {
}
//取得连接
Connection conn = null;
try {
//url是你的数据库地址,userid是登录名,password是密码(这几个参数你再看一下你自己的driver里是怎么要求的)
conn = 你的driver.getConnection(url, userid, password);
if (conn == null) {
System.out.println("Connection is null");
}

解决方案 »

  1.   

    String    drv = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
       String    url = "jdbc:microsoft:sqlserver://127.0.0.1:1433";
       String    uid = "sa";
       String    pwd = "123456";   Connection cn=null;
       try
       {
         Class.forName(drv).newInstance();
         cn=DriverManager.getConnection(url,uid,pwd);
       }
       catch (Exception e)
       {
       e.printStackTrace();
       }
      

  2.   

    要把你使用的jdbc目录下的三个jar文件拷贝到你的web目录的web-inf/classes/lib下。
    如果没有lib文件夹,就新建一个。
      

  3.   

    String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
      String sConnStr = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=mydb";