java.sql.SQLException: Operação inválida para encaminhar apenas conjunto de resultados  XML
Índice dos Fóruns » Java Básico
Autor Mensagem
proteus_adi
JavaGuru
[Avatar]

Membro desde: 24/11/2004 10:05:10
Mensagens: 237
Localização: Belo Horizonte -
Offline

ERRO REPORTADO:

java.sql.SQLException: Operação inválida para encaminhar apenas conjunto de resultados: first

QUE COISA É ESSA!

"Remember Yesterday and think about tomorrow... but you have to live today"

Existe vitória e existe derrota.
O segundo lugar é o primeiro dos que perderam.
[Email] [MSN]
Luiz Henrique Coura
Java Ninja
[Avatar]

Membro desde: 28/04/2004 21:03:05
Mensagens: 283
Localização: Lorena-SP
Offline

Coloca o erro todo e o trecho do código tb.
Só com isso fica difícil saber qual o problema.


"A única pergunta estúpida é aquela que você nunca faz"
Anônimo

Luiz Henrique Coura
[MSN]
thingol
Moderador

Membro desde: 29/07/2004 16:10:13
Mensagens: 17543
Offline

Bom, estou copiando o javadoc abaixo, e ele diz o seguinte:
se você chamou o método first, mas criou o resultset com a opção padrão (sem passar parâmetro nenhum para createStatement, por exemplo), o erro vai ocorrer.

[i]

boolean first ( ) throws SQLException

Moves the cursor to the first row in this ResultSet object.


Returns:
true if the cursor is on a valid row; false if there are no rows in the result set
Exceptions:
SQLException if a database access error occurs or the result set type is TYPE_FORWARD_ONLY
...

A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, it is possible to iterate through it only once and only from the first row to the last row. New methods in the JDBC 2.0 API make it possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options.



[/i]

[WWW]
proteus_adi
JavaGuru
[Avatar]

Membro desde: 24/11/2004 10:05:10
Mensagens: 237
Localização: Belo Horizonte -
Offline

try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@999.999.999.9:1521:orcl", "user", "passwd");

// Query the employee names
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from algo_tst");
// Print the name out

int n_rcount = 0;
int n_mod = 0;

/*rset.last();
n_rcount = rset.getRow();
rset.first();
while (rset.next()){
n_rcount++;
}

rset.first();
*/
n_rcount = rset.getFetchSize();
document.newPage();

Table table = new Table(3);
table.setBorderWidth(1);

n_mod = (int)(n_rcount/27);

for (int i= 0; i <=n_mod;i++){
Cell cell = new Cell("Relatório de lojas");
cell.setHeader(true);
cell.setColspan(3);
table.addCell(cell);
for(int j = 0 ; j < 10; i++){
table.addCell(rset.getString("id"));
table.addCell(rset.getString("nome"));
rset.next();
}
document.add(table);

}

}catch(Exception e){
e.printStackTrace();
document.newPage();
para=new Paragraph("ERRO REPORTADO" + e ,smallFont);
para.setAlignment(para.ALIGN_CENTER);
document.add(para);

// out.println(e);
}

document.close();

} catch (Exception e) {
e.printStackTrace();
}[b]

This message was edited 1 time. Last update was at 30/11/2004 15:47:39


"Remember Yesterday and think about tomorrow... but you have to live today"

Existe vitória e existe derrota.
O segundo lugar é o primeiro dos que perderam.
[Email] [MSN]
proteus_adi
JavaGuru
[Avatar]

Membro desde: 24/11/2004 10:05:10
Mensagens: 237
Localização: Belo Horizonte -
Offline

bom!!!
pelo jeito está dando erro nesse negocio de ir pra frente e pra traz!!

o que eu preciso declarar pra poder usar o
first();
e o last();

This message was edited 1 time. Last update was at 01/12/2004 10:28:42


"Remember Yesterday and think about tomorrow... but you have to live today"

Existe vitória e existe derrota.
O segundo lugar é o primeiro dos que perderam.
[Email] [MSN]
bokerao
Thread.start()
[Avatar]

Membro desde: 08/04/2009 14:16:02
Mensagens: 38
Offline

Estava com o mesmo problema ao usar o rs.first ou rs.last

Resolvi realmente usando a dica do colega acima

stmt = conn.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

Abraços

---------------
Bokerão - Eterno Padawan
OCJP 6
[WWW] [MSN]
 
Índice dos Fóruns » Java Básico
Ir para:   
Powered by JForum 2.1.8 © JForum Team