2
Good morning, my dear. I’m having trouble with jdbc. The connection to the bank is made but, does not bring anything with select. The eclipse console reported me some problems, such as: The proto-buf-java lib was missing, so I put the dependency on Maven. I’m using mysql BD, and I put the newest version of the connector. I put the getRow method, to indicate the number of lines that he’s picking up and redeveloped zero. First I’ll put connection class.
protected Connection getConnection() throws Exception,SQLException{
String driverName = "com.mysql.cj.jdbc.Driver";
try {
Class.forName(driverName);
}catch(ClassNotFoundException cne) {
System.out.println("Driver não encontrado");
}
try{
//Properties props = getProp();
String url = "jdbc:mysql://500.500.500.100:3306/sgbdmysql";
String usuario = "user";
String senha = "password";
//Conecta usando a URL, usuario e senha
Connection conn = DriverManager.getConnection(url, usuario, senha);
System.out.println(conn);
return conn;
}
catch(SQLException e){
System.out.println(e);
throw e;
}
}
Classse DAO
public Date getDataOperacao()throws Exception,SQLException{
Connection conn = null;
PreparedStatement stmt = null;
Date dta = null;
try {
conn = getConnection();
//Teste Mau - sucedido
String str = "SELECT dataoperacao FROM cimentacao_grafico WHERE well_name LIKE 'well3%' \n" +
" ORDER BY idgrafico DESC LIMIT 1";
//stmt = conn.prepareStatement("SELECT dataoperacao FROM cimentacao_grafico WHERE well_name LIKE 'well3%' \n" +
// " ORDER BY idgrafico DESC LIMIT 1");
stmt = conn.prepareStatement("SELECT * FROM cimentacao_hkloadcritico");
ResultSet rs = stmt.executeQuery();
System.out.println(rs.getRow());
if (rs.getRow() == 0) {
dta = new Date();
} else {
dta = rs.getDate("dataoperacao");
}
}finally {
if(stmt != null) {
stmt.close();
}
if(conn != null) {
conn.close();
}
}
return dta;
}
Look at the properties for me
isClosed
andisValid
of connection.– Augusto Vasques
The table
cimentacao_hkloadcritico
has records?– Reginaldo Rigo
Yes, there are four records to be exact.
– Peridev
You do not edit the title to mark as "solved". You accept the answer that actually solved your problem. In the absence of such a response, create your own response and accept it
– Jefferson Quesado
And how do you accept the answer I was given? I looked for somewhere to do this and I couldn’t find it. It’s been a long time since I used stackoverflow.
– Peridev