Ajuda no codigo!

1 resposta
R

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

1 Resposta

claudio

Cara,

poe no seu catch:

excep.printStackTrace();

e posta a saida aqui pra gente ver!

Abraço,

Criado 8 de outubro de 2003
Ultima resposta 8 de out. de 2003
Respostas 1
Participantes 2