尝试从大型数据集中获取数据 [英] Trying to get data from large dataset
问题描述
我正在为使用Java 1.7 + GAE的客户之一开发应用程序,并使用Google云端数据库以及数据库。
我试图获取数据从一个巨大的结果集,但我唯一得到它可怕的超时。
到目前为止,我有的代码是:
public List< String> leerMasivo(String cadena,String [] valores)throws SQLException {
log.info(Entra en lafunciónleer(String cadena,String [] valores));
this.conectar();
long nRowsNumber = 1;
long nId = 0;
列表< String> listaDatos = new ArrayList< String> ();
尝试{
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úmerode 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 lafunciónleer(String cadena,String [] valores));
return listaDatos;
如果你有时间的话,我需要告诉我什么都离开了,所以我可以得到我所需要的数据而不会出现超时错误。现在我对我可能缺少的东西一无所知。
感谢您的时间,
亲切的问候,
您可以在这里找到几种选择:
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,
You have several options here:
- consider using MapReduce library to operate on large datasets
- run this task on module with manual or basic scaling so there will be no time constraints
这篇关于尝试从大型数据集中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!