This error happens when executing any query in a table (Clientes).
package database;
import java.sql.*;
import java.util.Properties;
// Database Access Object
public class ClienteDao {
private Connection conexion = null;
public void conectar () {
String baseDeDatos = "pruebaLucas";
String usuario = "postgres";
String pass = "contra31";
String host = "localhost";
String puerto = "5432";
String driver = "org.postgresql.Driver";
String conexionUrl = "jdbc:postgresql://" + host + ":" + puerto + "/" + baseDeDatos +
"?user=" + usuario + "&password=" + pass + "&ssl=false";
try {
Properties props = new Properties();
props.setProperty("currentSchema", "schema_luki");
Class.forName(driver);
this.conexion = DriverManager.getConnection(conexionUrl, props);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private String construirQueryAgregarCliente (String cNombre, String cApellido, String cTel, String cEmail) {
return String.format(
"INSERT INTO Clientes (nombre, apellido, telefono, email)" + "VALUES (%s, %s, %s, %s);",
cNombre, cApellido, cTel, cEmail);
}
private void ejecutarQuery (String q) {
if (this.conexion != null) {
try {
Statement statement = this.conexion.createStatement();
statement.executeQuery(q);
statement.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
public void agregarCliente (String nombre, String apellido, String telefono, String email) {
this.ejecutarQuery( this.construirQueryAgregarCliente(nombre, apellido, telefono, email) );
}
}
I execute agregarCliente(...)
in a form (button click) and I get the error:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: relation "clientes" does not exist
Position: 13
at database.ClienteDao.ejecutarQuery(ClienteDao.java:41)
at database.ClienteDao.agregarCliente(ClienteDao.java:48)
at businessLogic.ManejadorClientes.agregarCliente(ManejadorClientes.java:15)
at frontend.DataForm$1.actionPerformed(DataForm.java:49)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6626)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389)
at java.desktop/java.awt.Component.processEvent(Component.java:6391)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
This is the structure of the Data base that I'm using (pruebaLucas):
How can I fix this problem? The connection look fine, It's something with the query.