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 8227959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:18:32+00:00 2026-06-07T16:18:32+00:00

I am trying to do something in my Application but I am stuck &

  • 0

I am trying to do something in my Application but I am stuck & unable to find a way forward. Here is my problem:-

I want to create Oracle Queries programatically. 2 such queries for e.g. are DROP TABLE tableName & ALTER TABLE tableName PRIMARY KEY (col1, col2, col3….);

In my class i have created these 2 final static Strings :-

private static final String DROP_TABLE = "DROP TABLE %1$s";

createDropStmt() {
    System.out.format(DROP_TABLE, tableName);
}

As you can see, this approach will work fine with DROP statements but not with PK’s beacuse I don’t know how may columns are going to be there till runtime. (private static final String PRIMARY_KEY = “ALTER TABLE %1$s PRIMARY KEY {don’t know what to put here}”`)

So, my question is how to do this kind of thing for PK so that my template string can dynamically take values & construct the query.? Does Java have a clean way to do it or my approach should be different?

Thanks

  • 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-07T16:18:34+00:00Added an answer on June 7, 2026 at 4:18 pm

    If you have multiple primary key columns then you have to join their names with commas. The java.util.Formatter doesn’t offer a way to concatenate arrays or lists of values. You have to do that for yourself.

    When you don’t want to write your own joiner, you could use the Joiner from the Guava libraries like this:

    Joiner.on(",").join(primaryKeyColumns);
    

    and then insert this into the ALTER TABLE statement.

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

Sidebar

Related Questions

I've been trying to get something working in a windows 8 metro style application,
I'm currently in a .NET4 Windows Forms Application. I'm trying to make something like
I have something I am trying to achieve. I have a web application running
I'm trying something like this, but this example does not work. jsObj = {};
I've been trying to find a good architecture for one application for the last
I'm converting a Castle/Monorails application into a Unity/Asp.NET MVC one, I'm stuck in trying
Well... I am trying to create an application using the TTS Engine. I can
I might be trying to do something impossible or really hard, but I wanted
Am trying to get qtip2 working with a rails3 application. qtip's working great but
I'm a Python & App Engine (and server-side!) newbie, and I'm trying to create

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.