Ir para conteúdo
Fórum Script Brasil

rafacarvalhido

Membros
  • Total de itens

    4
  • Registro em

  • Última visita

Posts postados por rafacarvalhido

  1. Fala amigo!

    Tenha cuidado aqui com a forma de conexão, até porque você não está vendo minha classe ConexaoBD. Mas como o seu problema é popular a combo, imagino que conexão com o banco você já tenha.

    Faz um select aí como tu sempre faz. E pra popular a combobox, usa um while pra adicionar items.

    private void populateCombo(){
            try{
                Connection con = ConexaoBD.createConnection();
                String sql = "SELECT * FROM \"alunos\" ORDER BY \"nome\"";
                PreparedStatement stm = con.prepareStatement(sql);
                ResultSet rs = stm.executeQuery();
                
                while(rs.next()){
                    String name = rs.getString("nome");
                    jComboBox1.addItem(name);
                }
            }catch(Exception e){
                JOptionPane.showMessageDialog(null, e);
            }
        }
    
  2. Hello, I´ve created a JForm (GUI) and added a JTable to it. Then right clicked the table and 'bind' -> 'elements'. So I imported the table I want from my database and the communication worked because the column names are now displayed on the table header.
    But when I run the program, it gives the following error:
    Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "cambio.publico.teste"
    Call: SELECT COD, NOME, TELEFONE FROM CAMBIO.publico.teste
      Posição: 33
    Query: ReadAllQuery(referenceClass=Teste sql="SELECT COD, NOME, TELEFONE FROM CAMBIO.publico.teste")
    Error Code: 0
    Call: SELECT COD, NOME, TELEFONE FROM CAMBIO.publico.teste
    Query: ReadAllQuery(referenceClass=Teste sql="SELECT COD, NOME, TELEFONE FROM CAMBIO.publico.teste")
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:378)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:469)
    at visao.TelaCaixa7.initComponents(TelaCaixa7.java:33)
    at visao.TelaCaixa7.<init>(TelaCaixa7.java:18)
    at visao.TelaCaixa7$1.run(TelaCaixa7.java:106)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:702)
    at java.awt.EventQueue$3.run(EventQueue.java:696)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
    Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "cambio.publico.teste"
      Posição: 33
    Error Code: 0
    Call: SELECT COD, NOME, TELEFONE FROM CAMBIO.publico.teste
    Query: ReadAllQuery(referenceClass=Teste sql="SELECT COD, NOME, TELEFONE FROM CAMBIO.publico.teste")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:682)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2002)
    at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2738)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2691)
    at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:495)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1168)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1127)
    at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:403)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1215)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1786)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1751)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
    ... 18 more
    Caused by: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "cambio.publico.teste"
      Posição: 33
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:305)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1007)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:642)
    ... 38 more
    
    I believe the problem is because the jtable can be edited and said editions are automaticaly recorded on the database table which it is not allowing.
    Is there a way to explicitly tell my postgres table to allow cross-reference?
    Also I may be way off and the root cause be something else entirely. Thanks for the help.
×
×
  • Criar Novo...