Olá a todos!
Sou iniciante em java e estou tento mtos problemas em fazer uma classe que acesse um banco de dados e execute um transação ja li varios turorias e minha classe esta dando o seguinte erro qd compilo:" postgres.stat.result"
O codigo segue abaixo:
import java.sql.<em>;
import java.awt.</em>;
import java.awt.event.<em>;
import javax.swing.</em>;
public class TransactionPairs {
public static void main(String args[]) {
String url = "jdbc:postgresql://localhost:5432/estagio";
String username = "postgres";
String password = "postgres";
Connection con = null;
Statement stmt;
PreparedStatement insert;
PreparedStatement select;
String updateString = "INSERT INTO estagio VALUES ('FUNCIONOU',3,20)";
String query = "select * from estagio";
try {
Class.forName( "org.postgresql.Driver" );
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url,username, password);
insert = con.prepareStatement(updateString);
select = con.prepareStatement(query);
con.setAutoCommit(false);
insert.executeUpdate();
select.executeUpdate();
con.commit();
con.setAutoCommit(true);
insert.close();
select.close();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String c = rs.getString("EMPRESA");
int t = rs.getInt("TOTAL");
System.out.println(c + " " + " " + t);
}
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
if (con != null) {
try {
System.err.print("Transaction is being ");
System.err.println("rolled back");
con.rollback();
} catch (SQLException excep) {
System.err.print("SQLException: ");
System.err.println(excep.getMessage());
}
}
}
}
}
Se puderem me ajudar!!!
Rodrigo