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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:55:49+00:00 2026-06-06T16:55:49+00:00

first of all, a preface: I’m writing a java class that creates temporary tables

  • 0

first of all, a preface: I’m writing a java class that creates temporary tables on a database using jdbc. I’m using JSE6 and Oracle 11XE as a test DB, but the class needs to be also DB2 compliant.

The temporary tables I’m trying to create come from a bigger one, and I do some filtering and aggregations on the data. The parameters I base my filtering on are decided by the user at runtime. One simplified example of what I’m trying to do is this:

CREATE TABLE temp_table AS (
    SELECT
           table1.department_id,
           SUM(CASE WHEN table1.number_1 < &1 THEN table1.number_1 ELSE 0 END)) AS column1              
    FROM
           table1
    GROUP BY table1.department_id
)

My problem is that I need to specify parameters to filter the data, and I need to be sure they’re properly escaped/localized/typed. This would be easy using a prepared statement, but I cannot use bind variables with DDL.
The temporary solution I resorted to is to alter the query String myself, writing the parameters in the correct place, but this means I now have to implement all the checks instead of relying on a PreparedStatement object to do it for me, on top of losing all the other benefits.

I investigated other solutions, but none of them convinced me so far:

  1. I could first create an empty temp_table and then fill it with INSERT INTO temp_table(id, column1) (SELECT …) but it seems I might incur in performance loss, so I’d like to stick to the CREATE temp_table AS

  2. I thought about creating a temporary statement to hold the inner SELECT query, and have it generate a properly formatted/localized/etc. query string, but I haven’t found any way to obtain the final query from it (and I read it’s definitely not possible here). The only option I found for this case is to use DebuggableStatement, but I’m not sure I can include it in the project (also, it seems a quite inelegant way of solving my problem)

  3. Another solution I’m thinking of, is to simply put the queries that create the temporary tables (for each of them I’d put the whole CREATE AS (SELECT…) on the database, inside a procedure, which I’ll then be able to call using CallableStatement. this way I could avoid handling typization and still have good performances, at the price of a tighter coupling with the db (I’d have to be sure the procedures are there, or manage in java their addition/removal from the db)

So, my question is: are there better alternatives than the ones I could think of?

  • 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-06T16:55:53+00:00Added an answer on June 6, 2026 at 4:55 pm

    Is this supposed to be database agnostic, or are you targeting for only Oracle? You don’t have to store PL/SQL in a stored procedure to use it; just build an anonymous PL/SQL block that does what you need, and execute it. The anonymous PL/SQL block can be built dynamically so that strongly typed variables are declared in the PL/SQL to hold your parameters, and then your java code sticks the values in. The type safety wouldn’t be handled by Java since you’re just building a string; it would be handled by Oracle when you execute the anonymous PL/SQL block.

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

Sidebar

Related Questions

First of all, I'm quite new to the Android and JAVA world (coming from
First of all, let me clarify that I know you cannot have actual abstract
First of all, I got this huge xml file that represents data collected by
First all, I am still learning CakePHP and I am close to ZERO using
First off, let me preface this question by stating that I'm really a pretty
First off, let me preface this question by saying that my professor is firmly
I'll preface this question by stating that I'm using Oracle 10g Enterprise edition and
First of all, I know how to build a Java application. But I have
First of all, I'm using KohanaPHP Framework. I've impletemented SWFUpload successfully, working quite nice.
First of all, i would like to explain my condition right now. I'm using

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.