Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

java - Trying to get data from large dataset

I am developing an application for one of our clients using Java 1.7 + GAE, and using Google cloud sql as well as database.

I am trying to get data from a huge resultset, but the only thing i get its the dreaded timeout.

So far, the code i have is the following :

public List <String> leerMasivo(String cadena, String [] valores) throws SQLException{
    log.info("Entra en la función leer(String cadena, String [] valores)");
    this.conectar();
    long nRowsNumber = 1;
    long nId = 0;
    List <String> listaDatos = new ArrayList <String> ();
    try{
        while (nRowsNumber > 0) {
            nRowsNumber = 0;    
    PreparedStatement stmt = con.prepareStatement(cadena, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    stmt.setMaxRows(10);

    System.out.println("Número de filas maximo "+stmt.getMaxRows());        
    if(valores != null){
        for(int i=0; i< valores.length;i++){
            stmt.setString(i+1,valores[i]);
        }
    }
    ResultSet rs = stmt.executeQuery();
    ResultSetMetaData rsmd = (ResultSetMetaData) rs.getMetaData();
    int numeroColumnas= rsmd.getColumnCount();

    while (rs.next()){
        ++nRowsNumber;
        nId = rs.getLong(1);
        if (numeroColumnas >1){
            String fila ="";
            for (int i=1;i<=numeroColumnas;i++){
                    fila=fila + "::" + rs.getString(i);
            }
            fila=fila+"%%";
            listaDatos.add(fila);
        }else{
            listaDatos.add(rs.getString(1));
            }
        }
    }
    log.info("Los valores leidos son: " + listaDatos.toString());
    }catch(Exception e){
        log.info("Ha ocurrido un error" );
        log.info("el error es " + e.getMessage().toString());
        con.close();
        e.printStackTrace();
    }finally{
        this.cerrarConexion();
    }
     log.info("Sale de la función leer(String cadena, String [] valores)");

    return listaDatos;

}

I require, if you have the time, to tell me whats left so i can get the data i need without getting the timeout error. Right now i am clueless on what i could be missing.

Thank you for your time,

Kind regards,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...