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

  • SEARCH
  • Home
  • 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 8267569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:34:52+00:00 2026-06-08T05:34:52+00:00

I have a code in java that connects with postgreSQL database. now, I want

  • 0

I have a code in java that connects with postgreSQL database.

now, I want that when it connects to the database, i will also create database table.

but my problem is that, it will not create the database, and I don’t know what is the problem.

here is my code:

Statement st = null;
        ResultSet rs = null;
        try{
            Class.forName("org.postgresql.Driver");
            System.out.println("connect");
            } catch (ClassNotFoundException cnfe){
              System.out.println("Could not find the JDBC driver!");
              System.exit(1);
            }
        Connection conn = null;
        try {
            //database location, database user, database password
            conn = DriverManager.getConnection
                           ("jdbc:postgresql:"POS_DB","postgres", "123456");
            st = conn.createStatement();
            String qs = "CREATE TABLE IF NOT EXISTS user(user_id SERIAL NOT NULL PRIMARY KEY,username varchar(225) NOT NULL UNIQUE,password varchar(225),islogged varchar(10))";
            String qs1 = "SELECT * FROM test";
        rs = st.executeQuery(qs);

            System.out.println("connect");
             } catch (SQLException sqle) {
               System.out.println("Could not connect");
               System.exit(1);
             }

I am sure that my sql statement in creating the table is correct. but when I run this, it will not create the table. If I replace the string into select sql, there is no problem.

does anyone have an idea about my case?

thanks in advance ..

  • 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-08T05:34:54+00:00Added an answer on June 8, 2026 at 5:34 am

    This line :

    conn = DriverManager.getConnection
                           ("jdbc:postgresql:"POS_DB","postgres", "123456");
    

    is invalid.

    You have a " before POS_DB that should’nt be here.

    Too see some example check the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Java code that connects to an Oracle database using DriverManager.getConnection(). It
I have Java code that connects to an SQL server DB but I cannot
I have existing java code and need to create Design Document based on that.
I recently have a problem that my java code works perfectly ok on my
I have (java) code that creates and populates tables in a derby database, using
I have a desktop app in Java that connects to a MySql database through
I have a java application that connects to a database. The user name and
I have a Java application that connects to a MySQL database and uses a
I have code in Java that has an outer loop and several nested loops.
i have a question , i have this timer code in java that when

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.