OPDB-->是他写的一个类名字
其他的好象不用改先去下载sql server的jdbc驱动,-->有三个哦,然后放到你的站点的web-inf/lib/下然后改数据库的连接就行这里是一个例子try{
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myweb";
String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from [user]";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
    System.err.println(rs.getString(1));
    System.err.println(rs.getString(2));
 }
System.err.println("success");
    }catch(Exception ex){
        ex.printStackTrace();
    }

解决方案 »

  1.   

    楼上说的差不多了,OPDB-->是自己创建的一个类,这个类主要是初始化一些数据库连接的参数,你可以不改,要是觉得他写的不好,你也可以直接自己写一个连接数据库的类!
    由于java连接数据库用的是jdbc,每种数据库都有不同的数据库驱动,你要连接sql server2000的话,你就要上网下载sql server2000的驱动包,这三个包是以.jar结尾的,你可以把这三个包放在tomcat下的common下的lib文件夹中,或者放在你的web应用服务,也就是web-inf下的lib里都行!要是你在jbuilder中运行你的程序的话,你还需要把这三个包引用进来,具体的引用方法如下:
    右键点击你的工程--》选择最后一项--》选择required libraries--》add--》new,然后把那三个jar文件引用进来就可以了
      

  2.   

    差不多吧,我前一阵也一直为这个费了半天劲。注意二楼的System.err.println(rs.getString(1));一定要改为System.err.println(rs.getString("1"));一定要加引号!!!!
      

  3.   

    晕 to liuxiawei1(vivi)加什么引号??
      狂晕System.err.println(rs.getString(1));你说说看加上引号是什么意思呵呵
      

  4.   

    晕真不知道怎么说了你多看看书吧不要懂一点,就在这里乱说这个1对应是比如数据表有如下字段id name  password在得到一个rs对象后,你可以用rs.getString(1)和rs.getString("id")得到一样的效果不行你去试试
      

  5.   

    各位老大   我按大家说的改了一下
    package database;import java.sql.*;import java.util.*;
    import sun.io.*;public class OPDB{Connection conn =null;Statement sqlStatement =null;ResultSet results =null;ResultSet retemp =null; ResultSetMetaData resultsMeta =null;boolean status;String sql;int columns;long rowcount =0;//连接数据库public void connection(){try{
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wanghuanhuan";
    String user="wanghuan";
    String password="wanghuan";
    Connection conn= DriverManager.getConnection(url,user,password);this.status =true;}catch(Exception e){this.status =false;}}//连接数据库/*public void connection(String con,String username,String password){try{DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver);.
    this.conn =DriverManager.getConnection (con,username,password);this.status =true;}catch(SQLException e){this.status =false;}}
    */
    // 返回连接 public Connection getConn(){/* try{
    DBConnectionMannager connMgr;
    connMgr = DBConnectionMannager.getInstance();
    Connection conn =connMgr.getConnection("sz_hk");
    if(conn !=null)
    this.status =true;else 
    this.status =false;
    }catch(Exception e){
    System.out.println( e.toString());
    }*/
    return this.conn ;}// 关闭对数据库的连接等。 public void Close(){try{if(this.conn !=null)this.conn.close();if(this.sqlStatement !=null)this.sqlStatement.close();if(this.results !=null)this.results.close();//this.connMgr.release();
    this.status =true;
    }catch(SQLException e){this.status =false;}}//从数据库中选择数据public synchronized ResultSet select(Connection c,String sql){int index =0;//Assign passed argumentsthis.conn =c;this.sql =sql;try{//Create Statement Object and Execute SQLsqlStatement =this.conn.createStatement();retemp =sqlStatement.executeQuery(this.sql);this.rowcount =0;//Get the column count for the result setthis.rowcount =0;while(this.retemp.next())this.rowcount++;if(retemp!=null)retemp.close();results =sqlStatement.executeQuery(this.sql);resultsMeta =results.getMetaData();this.columns =resultsMeta.getColumnCount();this.status =true;return results;}catch(SQLException e){this.status =false;return null;}}//返回结果集的列数目 public int getColumns(){return this.columns;}//返回结果集的行数目 public long getRowcount(){return this.rowcount;}// 修改数据库中的记录。public synchronized void update(Connection c,String sql){try{Statement sqlStatement =c.createStatement();sqlStatement.executeUpdate(sql);status =true;}catch(SQLException e){//set status to flasestatus =false;}}//向数据库中插入记录。 public synchronized void insert(Connection c,String sql){try{Statement sqlStatement =c.createStatement();sqlStatement.executeUpdate(sql);//set status variable to truethis.status =true;}catch(SQLException e){//set status variable to truethis.status =false;}} // 删除记录 。public synchronized void delete(Connection c,String sql){try{sqlStatement =this.conn.createStatement();sqlStatement.executeUpdate(sql);status =true;}catch(SQLException e){//set status to flasestatus =false;}}//删除所有记录。public void deleteAll(String table){String sql ="delete from "+table;try{sqlStatement =this.conn.createStatement();sqlStatement.executeUpdate(sql);status =true;}catch(SQLException e){status =false;}}//返回对数据库的操作是否成功public boolean getSuccess(){return this.status;}//转换为中文字符public String GBK(String action){try{byte[] b =action.getBytes("GB2312");String convert =new String(b,"8859_1");return convert;}catch(Exception e){}return null;}
    public static String AsciiToChineseString(String s)
    {
    char[] orig =s.toCharArray();byte[] dest =new byte[orig.length];for(int i=0;i<orig.length;i++)dest[i] =(byte)(orig[i]&0xFF);try{
    ByteToCharConverter toChar =ByteToCharConverter.getConverter("gb2312");
    return new String(toChar.convertAll(dest));}catch(Exception e){}return s;
    }
    public String replace(String con ,String tag,String rep){
    int j=0;
    int i=0;
    int k=0;
    String RETU="";
    String temp =con;
    int tagc =tag.length();
    while(i<con.length()){
    if(con.substring(i).startsWith(tag)){
    temp =con.substring(j,i)+rep;
    RETU+= temp;
    i+=tagc;
    j=i;
    }
    else{
    i+=1;
    }}
    RETU +=con.substring(j);
    return RETU;
    } }可是又出现了如下问题:
      

  6.   

    /chat/confirm.jsp:66: cannot find symbol
    symbol  : class Vector
    location: class _jsp._chat._confirm__jsp
    Vector UserName=null;  
            ^
    /chat/confirm.jsp:67: cannot find symbol
    symbol  : class Vector
    location: class _jsp._chat._confirm__jsp
    UserName= (Vector)application.getAttribute("UserName");
                       ^
    /chat/confirm.jsp:69: cannot find symbol
    symbol  : class Vector
    location: class _jsp._chat._confirm__jsp
    UserName= new Vector(30,10);      
                                  ^
    Note: D:\Program Files\resin-pro-3.0.9\webapps\bbs\WEB-INF\work\_jsp\_chat\_confirm__jsp.java
    uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: D:\Program Files\resin-pro-3.0.9\webapps\bbs\WEB-INF\work\_jsp\_chat\_confirm__jsp.java
    uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    3 errors
      

  7.   

    加入oracle的驱动程序,改变连接数据库的url。最后一个问题,没有import需要的包或类。
      

  8.   

    加入一个包import java.util.Vector
    你用到那个类,就要把它import