-1
I am using this way to try to bring the latest information registered in sql server, but for some unknown reason it is not working. I searched in several forum and apparently is used the same method I am using:
Class.forName(Auxiliar1.AcessoBanco.getDriver());
Connection con = DriverManager.getConnection(Auxiliar1.AcessoBanco.getUrl(), Auxiliar1.AcessoBanco.getUser(), Auxiliar1.AcessoBanco.getPass());
String query1 = "Select MAX(ExtA_IndParafuso) FROM L11";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query1);
jTextField6.setText(rs.toString());
JOptionPane.showMessageDialog(null, rs.getInt(0));
I’m trying to bring the result in the form of Joptionpane
or in the format of Jtextfield
for testing.
I used it this way to try to bring the values and yet without success.
int valor = rs.getInt(0);
jTextField6.setText(String.valueOf(valor));
Isn’t it exactly the same doubt I answered? From the code it seems you didn’t try as I explained it.
– user28595
Well, there we went in a question and we ended up bringing the matter of time, as I am very doubtful in this part and I researched again and I’m sure other people will also have, I thought valid to bring a topic just for your doubt.
– Lucas16
I suggested a query for sql server that returns the last line.
– user28595
Yes @Articuno, but with it did not return anything, with this by menso returns something.
– Lucas16
In fact it even returns, but returns the same thing. 'Sqlserverresultset:3' adding +1 every 5 sgundos.
– Lucas16
I took the time question and even so it returns the same way, but without adding +1
– Lucas16
Tried to search a DBMS instead of via programming? If not, do it and compare the results
– user28595
yes, the "Select Max" brings me the value. Is it not because of st or rs?
– Lucas16
That is the mistake:
jTextField6.setText(rs.toString());
realizes that he’s turning the resultset into a string and not picking up what he returned?– user28595
in this case how can I do? I can’t bring it float or int
– Lucas16
It depends on the type of this field. The right way is to recover by the getters of the resultset, where it is usually getXXX, and this XXX is the type of the field. If you don’t know which one to use, read the resultset documentation and see the type most suitable for the field you are researching.
– user28595
Ok, in my case I need to bring values like float.
– Lucas16
If it is float, why ta using getint? You looked at the link I sent?
– user28595
Yes, but I tried with int to see if it would work. I looked yes, but I did not understand very well.
– Lucas16