Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8673211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:24:01+00:00 2026-06-12T19:24:01+00:00

I tried to make an insert to my postgres database with Java. I have

  • 0

I tried to make an insert to my postgres database with Java. I have default configuration for my local database.

I want to put some data in a table and I have some issues.

Here is the code :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public static void main(String[] args) {

    Connection con = null;
    PreparedStatement pst = null;

    String url = "jdbc:postgresql://localhost/postgres";
    String user = "postgres";
    String password = "thanassis";

    try {


        con = DriverManager.getConnection(url, user, password);

        String stm = "INSERT INTO TEST2(ID) VALUES(?)";
        pst = con.prepareStatement(stm);
        pst.setInt(1, 1);

        pst.executeUpdate(); 

    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(PreparedStatement.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);

    } finally {

        try {
            if (pst != null) {
                pst.close();
            }
            if (con != null) {
                con.close();
            }

        } catch (SQLException ex) {
            Logger lgr = Logger.getLogger(PreparedStatement.class.getName());
            lgr.log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
}

And here the exceptions

SEVERE: ERROR: relation "test2" does not exist
  Position: 13
org.postgresql.util.PSQLException: ERROR: relation "test2" does not exist
  Position: 13
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2101)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1834)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:332)
    at test.Test.main(Test.java:30)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:24:02+00:00Added an answer on June 12, 2026 at 7:24 pm

    Your table is called TEST2 not test2. Apparently you created it using double quotes, which makes Postgres (and other standard-compliant DBMS) case-sensitive.

    Because of that you now have to enclose the table in name in double quotes each time you refer to it.

    String stm = "INSERT INTO \"TEST2\"(ID) VALUES(?)";
    

    Most probably this is not what you intended, so just re-recreate the table without using double quotes around the identifiers:

    CREATE TABLE test2
    (
      ...
    )
    

    create a different table than:

    CREATE TABLE "test2"
    (
      ...
    )
    

    If you do not want to re-create the tables, you can rename them:

    alter table "TEST2" rename to test2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning programming and I've wanted to make some basic data structures. I tried
I've tried to make a method, which insert some numbers in a zedgraph. But
I want make sql query which will insert values from one table to another
I need to create an SQL query to insert some data into a table
I tried to make an asynchronous UDP client using boost::asio I get some code
I tried to make admin panel and I am using sessions , but have
I am trying to export some data from a SQL Express table to Access
OK, I've tried everything, just can't make this to work: I have the following
I have a site that displays data on travel products from a MySQL database.
I am tying to make a user system with a mysql database. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.