Convert a ResultSet

Forum sobre a ferramenta Oracle JDeveloper, ADF, OAF, etc. (Não é destinado ao aprendeziado da Linguagem Java em geral)
Post Reply
TauMan
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 3
Joined: Wed, 28 Oct 2009 5:54 pm
Location: Braga

The idea is as follows, I do a resultset and get a result, I need to convert this result to integer.

The idea is as follows, I make a query at BD to know how much elements have a particular column and wanted the result in a variable of type int, to do?
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

And only you do ...

Select all

 
ResultSet rs = cod.executeQuery("select count(coluna) as counter from tabela"); 
 
if (rs.next()) { 
   int contador = rs.getInt("counter");   
} 
TauMan
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 3
Joined: Wed, 28 Oct 2009 5:54 pm
Location: Braga

Your suggestion is capable of functioning in the case of int

Suppose I have the following table:

Select all

codigo | nome | saldo
and I want to know the name that is associated with the Code X, I do a

Select all

ResultSet rs = st.executeQuery("Select nome for tabela where codigo = x");
and then as I step on this information for string.

Thanks.
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

You spoke of int now string .. what do you want?

The interface [url=http://java.sun.com/j2se/1.4.2/docs/api ... ltSet.html]ResultSet of Java has all the necessary methods to pick up the various types of data, including blob ..

Do you want string? ... use

Select all

rs.getString("nome_da_coluna")
...

if you want to boost your query you will have to use [url=http://java.sun.com/j2se/1.4.2/docs/api ... ement.html]PreparedStatement and start do an executeQuery () to get a resulse
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests