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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:41:54+00:00 2026-05-30T06:41:54+00:00

I have this sql script that I would like to execute in a java

  • 0

I have this sql script that I would like to execute in a java program. It takes on 3 parameters: dropper_id, to_char(begin_dt), to_char(end_dt). How would I do this?

The program is held on a Unix server.

The sql script is also located on the Unix server.

I think i would most likely want to execute the program by command line, but how do I execute it with parameters?

Process p = Runtime.getRuntime().exec ("psql sql_script.sql");
  • 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-05-30T06:41:55+00:00Added an answer on May 30, 2026 at 6:41 am

    You can do that using JDBC and PreparedStatement, see these tutorials:

    • http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
    • http://www.commandprompt.com/ppbook/x20921

    Here are some examples:

    • http://www.exampledepot.com/egs/java.sql/InsertPs.html
    • http://www.roseindia.net/jdbc/jdbc-mysql/TwicePreparedStatement.shtml
    • http://www.roseindia.net/jdbc/prepared-statement-example.shtml
    • http://www.heimetli.ch/jdbc/JDBCPreparedStatement.html

    If both your Java application and the SQL are located on the same server, then you just need to load it and execute as given above. See examples here:

    • http://www.coderanch.com/t/306966/JDBC/java/Execute-sql-file-java
    • How to execute .sql script file using JDBC
    • Running a .sql script using MySQL with JDBC

    If it’s just running the SQL (i.e. the whole purpose of your application is to run that SQL and do nothing else), you may want to look at the alternative solutions such as using Ant for the task, see this:

    • http://ant.apache.org/manual/Tasks/sql.html

    or using whatever is your database command line utility, see some examples here:

    • How to execute sql-script file in java?

    This very much depends on your circumstances, so you would have to see what is important in your case to decide which way to go.

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

Sidebar

Related Questions

I have a script in T-SQL that goes like this: create table TableName (...)
If I have a SQL script stored in a variable like this: DECLARE @SQL
I have a sql script file that upon import creates a table in a
I have a Moose class that i would like to store using Apache::Session::File. However,
I have a pagination script that displays a list of all pages like so:
I have a SQL script that inserts data (via INSERT statements currently numbering in
I have a SQL script that is setting up two database tables with their
I have a script that generates an SQL query as text e.g. ... return
I have a script with a few hundreds of sql queries that I need
I have a very long T-sql script, it is a single batch, something like

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.