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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:00:41+00:00 2026-06-07T08:00:41+00:00

I need to define some variables in Oracle to be used further down our

  • 0

I need to define some variables in Oracle to be used further down our application’s database installation scripts. Basically, the way our installer works now is it reads in the script files and calls each one via JDBC in Java. I need to have Oracle do the variable substitution on the database side, as there are procedures, triggers, create statements, etc. that will need to refer to them (So like “CREATE TABLE &&MYSCHEMA.TBL_NAME …”).

The problem I am having is that the DEFINE statement is throwing an error when calling it from Java (example):

private static void testDefineVariables() {
    String url = "jdbc:oracle:thin:@localhost:1521:LOCALDEV";
    String username = "SYSTEM";
    String password = "manager42";
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = DriverManager.getConnection(url, username, password);
        stmt = conn.createStatement();

        //Execute the sql
        stmt.execute("DEFINE MYSCHEMA='TESTSCHEMA'");

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally {
        try {

        if(stmt != null)
            stmt.close();

        if(conn != null)
            conn.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

The error is:

java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:194)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1000)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1882)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1847)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:301)

I am using an Oracle 11g R2 database with the ojdbc6-11.2.0.1.0.jar JDBC driver. I am able to execute the statement successfully from the sqldeveloper tool as well as the SQLPlus console, but not from the Java application. Do I need to configure additional properties on the database driver? Can I make this type of call from this driver?

I know some people right off the bat may suggest using variable bindings on the Java side, but this is not an option. The scripts need to be executable from both the SQL interface and the installer. There are other reasons apart from this one, which I won’t go into.

I am also hoping to get this to work with the sql-maven-plugin, but that may not be possible based on this JIRA:

Add Oracle SQLPlus syntax for substitution variables

If anyone has any suggestions or know how to get this to work, I would greatly appreciate it.

  • 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-07T08:00:44+00:00Added an answer on June 7, 2026 at 8:00 am

    Both DEFINE and the substitution variable syntax &&MYSCHEMA.TBL_NAME are SQL*Plus commands. They are not valid SQL or PL/SQL constructs. You won’t be able to use them as-is via JDBC.

    Depending on the reasons that you say you don’t want to go into

    • Your Java application can call out to the operating system to invoke SQL*Plus and pass in the script
    • Your Java application can implement whatever SQL*Plus features your scripts rely on. Rather than executing DEFINE MYSCHEMA='TESTSCHEMA', your application would need to maintain, say, a HashMap that maps a variable like myschema to a value like TESTSCHEMA. Your application would then have to parse the individual SQL statements looking for text like &&MYSCHEMA, replace that with the value from its local HashMap, and then send the resulting SQL string to the database server. Depending on how much of the SQL*Plus functionality you need to replicate, that could be a reasonably significant undertaking. Many PL/SQL IDEs (such as Toad or SQL Developer) implement a subset of SQL*Plus’s functionality– I don’t know of any that have tried to implement every last SQL*Plus feature.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to define some constant strings that will be used only by one
I have a Base Router where i define some functions that need to be
I need to define an appender for log4net in a way that I get
I need to define an <img>'s src attribute in CSS. Is there a way
I need to define many variables and I don't want to do it one
How do or where do I define variables that can be used throughout an
I want to write reusable code and need to declare some variables at the
i've some public variables in my class, here is how i define them class
I've defined a DataTemplate in a ResourceDictionary. The template need some data (for populating
I have a design question. We need to put some default, system defined content

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.