在当前工程中用一个类的main方法或者JUnit。运行    String acct="测试数据";
    String pwd ="测试数据";
    Connection con = null;
    Statement st = null;
    StringBuffer msgb = new StringBuffer("");    try
    {
      // These will vary depending on your server/database      
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
      con = DriverManager.getConnection("jdbc:odbc:acctInfo");      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("Select balance from acctInfo where account = " +
                             acct + "and password = '" + pwd + "'");      
      if (rs.next())
        return rs.getString(1);
      else
        return null;
    }
    catch (Exception e)
    {
      return e.toString();
    }

解决方案 »

  1.   

    是新建一个类还是什么,但我启动服务器,也看不到有什么结果,jdbc:odbc:acctInfo这是在ODBC建立的一个数据源,应该不会有问题,问题是我现在怎样验证返回的数据是我想要的
      

  2.   

    我是在这里加了一句,但好像不行
        try
        {
          // These will vary depending on your server/database
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con = DriverManager.getConnection("jdbc:odbc:acctInfo");      Statement stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery("Select balance from acctInfo where account = " +
                                 acct + "and password = '" + pwd + "'");
          stmt.executeQuery("insert into acctInfo values('55','55','55')");//这句是我加上去测试的
          if (rs.next())
            return rs.getString(1);
          else
            return null;
        }