sql - Calling Oracle "DEFINE" from Java -


I need to define some variables in Oracle so that our application's database installation script can be used more and more. Actually, the way our installer works now, it reads in script files and calls everyone in Java via JDBC. There are as procedures, triggers make statements, etc. that will need to refer to them (like I, Oracle Database on Create variables requires replacement "table and & amp; MYSCHEMA.TBL_NAME ... ").

I have an issue that the defining statement is throwing an error when calling it to Java (example):

  Private static zero testing Defibrillas () {string Url = " Jdbc: oracle: thin: @localhost: 1521: LOCALDEV "; String user name = "system"; String password = "manager 42"; Connection Conn = Null; Description stmt = null; Try {conn = DriverManager.getConnection (URL, Username, Password); Stmt = conn.createStatement (); // execute SQL stmt.execute ("defined MYSCHEMA = 'TESTSCHEMA'"); } Grip (SQLException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); } Finally {try {if (stmt! = Null) stmt.close (); If (conn! = Null) conn.close (); } Hold (SQLException e) {e.printstaxtrace (); }}}   

Error:

  java.sql.SQLSyntaxErrorException: Invalid SQL statement on ORA-00,900: oracle.jdbc.driver.T4CTTIoer. On processError oracle.jdbc.driver.T4CTTIoer.processError (T4CTTIoer.java:395) to (T4CTTIoer.java:439) oracle.jdbc.driver.T4C8Oall.processError (T4C8Oall.java:802) on oracle.jdbc.driver.T4CTTIfun on .receive oracle.jdbc.driver.T4CTTIfun.doRPC (T4CTTIfun.java:436) (T4CTTIfun.java:186) on oracle.jdbc.driver.T4C8Oall.doOALL (T4C8Oall.java:521) on oracle.jdbc.driver. Oracle.jdbc.driver at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout (OracleStatement.java:1307) at oracle.jdbc.driver.T4CStatement.executeForRows T4CStatement.doOall8 (T4CStatement.java:194) .OracleStatement.executeInternal (OracleStatement. java: 1882) oracle.jdbc.driver.OracleStatement.execute (OracleStatement.java:1847) on oracle.jdbc.driver.OracleStatementWrapper.execute (OracleStatementWrapper.java:301)   

I I'm using an Oracle 11GR2 da Ojdbc6-11.2.0.1.0.jar Photos with JDBC driver. I am able to successfully execute the statement with the sqldeveloper tool from the SQLPlus console, but not from the Java application. Do I need to configure additional properties on the database driver? Can I make this kind of call from this driver?

I know that some people from BAT may get the suggestion of using variable binding on the Java side, but this is not an option. Scripts should be executable from both the SQL interface and the installer. There are also other reasons, which I will not go inside.

I also hope that it works with the SQL-Amway plugin, but it may not be possible based on this:

If anyone I have a suggestion or how it works, I appreciate it.

itemprop = "text">

and the definition variable variation both the definition of; SQL * MYSCHEMA.TBL_NAME are plus orders; & Amp; They are not building valid SQL or PL / SQL. You will not be able to use them through JDBC.

Depending on the reasons stated to you that you do not want to go to your Java application

  • Open the SQL * plus and call the operating system to pass in the script
  • Whatever your Java application can use with SQL * Plus depends on your script. instead of executing, MYSCHEMA = 'TESTSCHEMA' to execute your applications typically require a Hasmap , say, that myschema As a map to a map, the value is like TESTSCHEMA as your app is then called & amp; Amp; & Amp; To search for text such as MYSCHEMA the individual SQL details must be parsed, replace it with the value from your local Hashmap , and then send the result to the SQL Server database server on the string SQL * plus functionality Depending on how important it is to repeat you, this can be an important important venture. Many PL / SQL IDE (such as Tod or SQL Developer) SQL * Plus activist Apply a subset of capability - I know that not every last SQL * plus feature has tried to implement.

Comments