dbf是foxpro的数据文件吧,我原来在win32下试过,用jdbc:odbc后边加上文件路径就可以了

解决方案 »

  1.   

    1.先用odbc建个数据源
    2.写连接字符串为jdbc:odbc:数据源名, 用sun.jdbc.odbc.JdbcOdbcDriver
    3.连上后取得Connection就可用了
      

  2.   

    String DBDriver = "sun.jdbc.odbc.test";
          String ConnStr = "sun.jdbc.odbc.JdbcOdbcDriver";
          Connection conn = null;
          ResultSet rs = null;
          String sRetVal="",lsStockName="",lsRecentPrice="",lsIntro="";      try {
             conn = javasql.DriverManager.getConnection(ConnStr);//老是提示这里非法字符,我不明白什么原因,要别的驱动吗? 
             Statement stmt = conn.createStatement();
             rs = stmt.executeQuery("select count(*) from dxgp where zqdm = '"+asReqStr+"'");
      

  3.   

    错了,上面是
    java.sql.DriverManager.getConnection(ConnStr);
    还是同样的提示,请高手帮小弟看看!
      

  4.   

    1.先用odbc建个数据源
    2.打开JB,-->tools-->JDBC explore--->New
    2.写连接字符串为URL:jdbc:odbc:odbcDataSource(jdbc:odbc:数据源名,)DRIVER: 用sun.jdbc.odbc.JdbcOdbcDriver
    3.-->OPEN
      

  5.   

    能不能再 帮我解释一下,我在JB中配置的数据源和ODBC中配置的是否一样?JB中配置的时候好想只能认jdx结尾的文件格式,我的是DBF的,如果方便你能不能举个例子,多谢,如果解决分就是你的!
      

  6.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String ConnStr="jdbc:odbc:IR";
    conn = javasql.DriverManager.getConnection(ConnStr);注意这里的 "IR"
    是你在机器中设的odbc与数据库连接的名字。
      

  7.   

    我的代码是这样的,能不能帮我看一下,编译通过,但运行时调用这个方法时总提示
    java.rmi.RemoteException: EJB Exception: ; nested exception is:
            javax.ejb.EJBException: GPQueryAttemper Exceptionjavax.ejb.EJBException:
     QueryStockMarket Exeception:java.lang.StringIndexOutOfBoundsException: String i
    ndex out of range: -5
    javax.ejb.EJBException: GPQueryAttemper Exceptionjavax.ejb.EJBException: QuerySt
    ockMarket Exeception:java.lang.StringIndexOutOfBoundsException: String index out
     of range: -5
     private String QueryStockMarket(String asReqStr){
          String ConnStr = "jdbc:odbc:test";
          Connection conn = null;
          ResultSet rs = null;
          Statement stmt = null;
          String sRetVal = "",   lsStockName= "";
          String lsRecentPrice= "",lsIntro= "";
          int liNum =0;
          boolean bErrorFlag = false;      try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             conn = DriverManager.getConnection(ConnStr);
             stmt = conn.createStatement();
             rs = stmt.executeQuery("select count(*) from dxgp where zqdm = '"+asReqStr+"'");
             rs.next();
             liNum = rs.getInt(1);
             if (liNum == 0)
                sRetVal = "";
             else {
               rs = stmt.executeQuery("select zqmc,zxj,hjdp from dxgp where zqdm = '"+asReqStr+"'");
               rs.next();
               lsStockName=rs.getString(1);
               lsRecentPrice=rs.getString(2);
               lsIntro=rs.getString(3);
               sRetVal = "代码"+asReqStr+"名称"+lsStockName.trim()+"最新价"+lsRecentPrice.trim()+"点评"+lsIntro.trim();
             }
          }catch(Exception e){
              sRetVal = "QueryStockMarket Exeception:"+e ;
              bErrorFlag = true ;
          }
          finally{
              try{
                  if(rs != null) rs.close() ;
                  if(stmt != null) stmt.close() ;
                  if(conn != null) conn.close();
              }catch(Exception e){
                  sRetVal = "QueryStockMarket Exeception:"+e ;
                  bErrorFlag = true ;
              }
              if(bErrorFlag) throw new EJBException(sRetVal);
          }
         return sRetVal ;
      }
      

  8.   

    我在ODBC中配置了一个系统dsn 命名为test,测试也通过的,可以连接,为什么在JB中还是不行?
      

  9.   

    rs = stmt.executeQuery("select count(*) from dxgp where zqdm = '"+asReqStr+"'");
    不对吧!应该是
    rs = stmt.executeQuery("select count(*) from dxgp where zqdm = asReqStr");
      

  10.   

    不会吧,asReqStr是参数啊,这个绝对没问题,是和数据库没连上,我不知道设么原因,数据源是好的!我用它在PB里可以连的!
      

  11.   

    1.你先注了
    if(bErrorFlag) throw new EJBException(sRetVal);
    能不能运行。
      

  12.   

    注销后提示
    QueryStockMarket Exeception:java.lang.NullPointerException
      

  13.   

    呵呵,抱歉,已解决!!一个小问题没注意!qiyao:分给你啦