Execute .sql file using JDBC
I have a .sql file which contains a SELECT query and spools the ouput into a .txt file.
The problem is, I have some formatting queries like SET LINESIZE 500 etc.
How do I execute the .SQL file
vignesh_shrinivasan wrote:
I have a .sql file which contains a SELECT query and spools the ouput into a .txt file.
The problem is, I have some formatting queries like SET LINESIZE 500 etc.
How do I execute the .SQL fileYou have a file which has SQLPLUS script.
Nothing you do will make SQLPLUS command statements work via JDBC.
There are only two options.
1. Create a PL/SQL which does the same thing.
2. Use SQLPLUS and do not use jdbc.
Similar Messages
-
Executing *.sql files from jdbc
Hi, does anyone know how can I execute an sql file using jdbc?
Please make me know, tnx.
RegardsCheck this out.
http://asktom.oracle.com/pls/ask/f?p=4950:8:14961192831279021580::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241, -
Compile a procedure /SQL file using JDBC?
Is there a way we can compile a procedure or even a smiple SQL file using JDBC?
Or in other words can "@ <file name with path>" be done using JDBC? Has anyone tried this before?
I have five different databases, and i want to be able to compile my stored procedures at once on all my 5 databases. So, if we know if this is possible in JDBC?
THanksright, as a matter of fact i wanted some pointers on how to run these SQL commands using JDBC.
Like, set serveroutput on
set feedback on
@ filename or start filename
show error
etc. -
How to execute .sql file using ODI
Hi All,
I need to execute .sql file using ODI.
I tried @{path}{file} command in ODI procedure selecting oracle technology.but it is failing.
Do any one have any other idea to execute .sql file.
Thanks in advanceOhk...I think you can try creating batch file(.bat) if its Windows & call that from ODIOSCommand.
The bat file should contain scripts which call .sql file using sqlplus & there you can use @{path}{file} format.
See if this helps.
Regards,
Santy -
How to execute .sql file in Stored Procedure?
Hi,
I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
This .sql file will have set of update statement. I need to pass value to this update statement.
Kindly please help me.
Regards,
IrfanThis is required as part of Data Migration where i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
How have you determined that it's "better" to have seperate scripts? I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
Question: Why do you have tables with different names that all need the same process doing to them?
Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
e.g.
create procedure update_table(tbl_name varchar2) is
begin
execute immediate 'update '||tbl_name||' set lastupdate = null';
end;
As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer. Please do take the time to read the FAQ and post appropriate details so people can help you. -
Is it possible to use Jdeveloper with Other Sql Server using JDBC-ODBC bri
I have been able to successfully establish connection with Sql server Using JDBC-ODBC bridge, but when i run the application and perform some operations such as insert the following errors occur:
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT ItmUnit.ORG_CODE, ItmUnit.UNIT_CODE, ItmUnit.UNIT_NAME, ItmUnit.ADDRESS1, ItmUnit.ADDRESS2, ItmUnit.ADDRESS3, ItmUnit.CITY_CODE, ItmUnit.USER_ID, ItmUnit.TIME_STAMP FROM ITM_UNIT ItmUnit
----- LEVEL 1: DETAIL 0 -----
(java.sql.SQLException) [DataDirect][ODBC Sybase Wire Protocol driver]Sybase does not allow more than one active statement when retrieving results without a cursor
(oracle.jbo.DMLException) JBO-26041: Failed to post data to database during "Insert": SQL Statement "INSERT INTO IMMS.HRM_UNIT(UNIT_CODE,UNIT_NAME) VALUES (?,?)".
----- LEVEL 1: DETAIL 0 -----
(java.sql.SQLException) [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt
(oracle.jbo.AttrValException) JBO-27014: Attribute DeptCode in HrmUnitDept is required
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT HrmUnit.UNIT_CODE, HrmUnit.UNIT_NAME FROM IMMS.HRM_UNIT HrmUnit
----- LEVEL 1: DETAIL 0 -----
(java.sql.SQLException) [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmtYes, you can do that. For testing purposes you can also create simple files (with mkfile) and add these to ASM. That way you could also experiment with deleting files and see what happens in ASM
Bjoern -
Hi,
I'm trying to execute sql files located in
unix environment using sqlplus from forms 6i
in windows Me environment. I give the full
directory like @/usr/users/oracle/toto.sql.
But an error occures telling me that file
cannot found (error SP2 0310).
I hpe deeply that you can help me, please.<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by dany:
Hi,
I'm trying to execute sql files located in
unix environment using sqlplus from forms 6i
in windows Me environment. I give the full
directory like @/usr/users/oracle/toto.sql.
But an error occures telling me that file
cannot found (error SP2 0310).
I hpe deeply that you can help me, please.<HR></BLOCKQUOTE>
Be carreful of upper/lower-case. Unix is case sensitive !! Maybe @/usr/users/oracle/toto.SQL or @/usr/users/oracle/Toto.Sql or ... -
How to execute SQL Script using windows powershell(using invoke-sqlcmd or any if)
OS : Windows server 2008
SQL Server : SQL Server 2012
Script: Test.sql (T-SQL) example : "select name from sys.databases"
Batch script: windows MyBatchscript.bat ( here connects to sql server using sqlcmd and output c:\Testput.txt)
(sqlcmd.exe -S DBserverName -U username -P p@ssword -i C:\test.sql -o "c:\Testoutput.txt) ---it working without any issues.....
This can execute if i double click MyBatchscript.bat file and can see the output in c:\testput.txt.
Powershell: Similarly, How can i do in powershell 2.0 or higher versions? can any one give full details with each step?
I found some of them online, but nowhere seen clear details or examples and it not executing through cmd line (or batch script).
example: invoke-sqlcmd -Servernameinstance Servername -inputfile "c:\test.sql" | out-File -filepath "c:\psOutput.txt" --(call this file name MyTest.ps1)
(The above script working if i run manually. I want to run automatic like double click (or schedule with 3rd party tool/scheduler ) in Batch file and see the output in C drive(c:\psOutput.txt))
Can anyone Powershell experts give/suggest full details/steps for this. How to proceed? Is there any configurations required to run automatic?
Thanks in advance.Testeted the following code and it's working.....thanks all.
Execute sql script using invoke-sqlcmd with batch script and without batch script.
Option1: using Import sqlps
1.Save sql script as "C:\scripts\Test.sql" script in side Test.sql: select name from sys.databases
2.Save Batch script as "C:\scripts\MyTest.bat" Script inside Batch script:
powershell.exe C:\scripts\mypowershell.ps1
3.Save powershell script as "C:\scripts\mypowershell.ps1"
import-module "sqlps" -DisableNameChecking
invoke-sqlcmd -Servername ServerName -inputFile "C:\scripts\Test.sql" | out-File -filepath "C:\scripts\TestOutput.txt"
4.Run the Batch script commandline or double click then can able to see the output "C:\scripts\TestOutput.txt" file.
5.Connect to current scripts location cd C:\scripts (enter)
C:\scripts\dir (enter )
C:\scripts\MyTest.bat (enter)
Note: can able to see the output in "C:\scripts" location as file name "TestOutput.txt".
Option2: Otherway, import sqlps and execution
1.Save sql script as "C:\scripts\Test.sql" script in side Test.sql: select name from sys.databases
2.Save powershell script as "C:\scripts\mypowershell.ps1"
# import-module "sqlps" -DisableNameChecking #...Here it not required.
invoke-sqlcmd -Servername ServerName -inputFile "C:\scripts\Test.sql" | out-File -filepath "C:\scripts\TestOutput.txt"
3.Connect to current scripts location
cd C:\scripts (enter)
C:\scripts\dir (enter )
C:\scripts\powershell.exe sqlps C:\scripts\mypowershell.ps1 (enter)
Note: can able to see the output in "C:\scripts" location as file name "TestOutput.txt". -
How to execute sql file from servlet
Hi,
I am using JSP, Servlets and Oracle 8i in my application. I want to execute .sql file from java code. Is it possible to do that,
as we execute .sql file from sql plus prompt.
Suppose I have abc.sql file and I want to execute it from java code.
If any body have the solution then pl. reply with sample code.
Thanks,
RajeshIf any body have the solution then pl. reply with
sample code.No, no, dec - s/he doesn't want the actual solution, but the full code!
/k1 -
How to execute .sql file
hi,
i want to execute .sql files in sql plus from a fixed location whether it may be network location or from system drive. so that i can use it from other computers when i will be working on different pc.
so please tell me for network location solution and from drive. by default it fetch from BIN directory
i am using oracle 10g.
thanksHi FRNzzz!! wrote:
if the .sql files are placed on some network place then also i just need to put the path of that directory ? Sure. You can either set up a desktop shortcut for SQL*Plus using the remote folder as the "Start in" location, or (what I usually do) drag the script file into your SQL*Plus window.
Edited by: William Robertson on Feb 26, 2011 2:21 PM -
Can't read special characters in an excel file using JDBC
Hi! I 've a code to read an excel file using JDBC-ODBC bridge. I can read the values, but any special characters is readed wrong, just symbols. The special characters are of spanish language. This is my code:
Locale currentLocale;
currentLocale = new Locale("es", "MX");
Locale.setDefault(currentLocale);
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=comisionesperfiles.xls");
stmnt = c.createStatement();
String query = "Select * from [Hoja1$]" ;
ResultSet rs = stmnt.executeQuery( query );
while( rs.next() ){
String valor = rs.getString(2) ;
if(valor != null && !"null".equalsIgnoreCase(valor)){
if(!comisiones.contains(valor)){
System.out.println(valor);
comisiones.add( valor );
rs.close();
stmnt.close();As you can see, I've tried to set the locale, but it didn't work.
I'm using Excel 2003, Java Version 1.4.2_07 and Windows XP Professional (in latin american spanish).
Hope someone can help me!FYI: Apache's POI can read/write Excel files in Java:
http://jakarta.apache.org/poi/index.html -
Oracle to SQL Server using JDBC
I would like to connect Oracle to SQL Server using JDBC and a java program in oracle using loadjava.
I cannot seem to get a SQL Server driver to work when loaded into Oracle using loadjava. Outside of oracle, they work just fine. Within oracle, I receive class not found exceptions.
PLEASE HELP!!!!!!!I would like to connect Oracle to SQL Server using JDBC and a java program in oracle using loadjava.
I cannot seem to get a SQL Server driver to work when loaded into Oracle using loadjava. Outside of oracle, they work just fine. Within oracle, I receive class not found exceptions.
PLEASE HELP!!!!!!! -
Execute wrapped .plb file using JDBC
We have a wrapped PL/SQL stired procedure that we would like to execute through our application that uses JDBC to connect to our repository database which resides on Oracle 9.2.
Using JDBC, we can issue statements like:
create or replace procedure my_proc(
var1 in varchar2,
var2 out varchar2) as ......
What we really need is the equivalent of Sql*Plus, where using Sql*Plus we could do the following:
SQL >@<file_location><script_file.plb>
where script_file.plb is a wrapped PL/SQL create or replace script.
Is there any way possible that this can be done ? If so please email this documenation or a link to it to me: [email protected]
Thanks.
FerencFerenc,
Read the file contents into a "String" and then invoke the "executeUpdate()" method (of "java.sql.Statement") using the "String".
Alternatively, use the "exec()" method (of "java.lang.Runtime") to execute "SQL*Plus", for example:
String[] cmd = new String[]{"path_to/sqlplus","@file"};
Runtime.getRuntime().exec(cmd);Note that above code is from memory only. Please verify using "javadoc" documentation.
Good Luck,
Avi. -
Executing .sql file in oracle using php
Hello friends
I am converting the oracle form into web application.
My requirement is to execute a .sql file when i click on a button in the html form.
What i need to do is when the user click on the button then the sql+ window shoudl open up and a file located on the server should get executed.
Please note i have to do this in php. If any other alternative is there for this requirement then that also is welcomed.
Any help would be appreciated.
Thanks
VinodThe thing is i am using
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
I am connecting to the DATABASE using
the below php code
=========================
<?php
if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
PutEnv("ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/");
PutEnv("LD_LIBRARY_PATH=-Wl,-rpath,/usr/lib/oracle/xe/app/oracle/product/10.2.0/server//lib -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/server//lib -lclntsh");
$dbstr ="(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XXX.XXX)(PORT = XXXX))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
if(!@($conn = oci_connect('SYSTEM','passwordString',$dbstr)))
print_r(ocierror());
else
echo "connected succesfully";
exit;
?>
========================
I am able to connect the database and ececute query and fetch the results.
Now one file will be present in some directory on the server let say abc.sql
Now i need to execute that file and display the output to the user by means of php code.
So please provide me the detailed step on how to get this done.
Thanks -
Loading big XML files using JDBC gives errors
Hi,
I've created a XMLType table using binary storage, with the restriction that any document stored has a (any) schema:
CREATE TABLE XMLBIN OF XMLTYPE
XMLTYPE STORE AS BINARY XML
ALLOW ANYSCHEMA;Then I use JDBC to store a relatively large document using the following code:
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String connectionString = "jdbc:oracle:thin:@host:1521:sid";
File f = new File("c:\\temp\\big.xml");
Connection conn = DriverManager.getConnection(connectionString, "username", "password");
XMLType xml = XMLType.createXML(conn,new FileInputStream(f));
String statementText = "INSERT INTO xmlbin VALUES (?)";
OracleResultSet resultSet = null;
OracleCallableStatement statement = (OracleCallableStatement)conn.prepareCall(statementText);
statement.setObject(1,xml);
statement.execute();
statement.close();
conn.commit();
conn.close();Loading a file of 61Mb (real Mb, in non-IT Mb (where 1Mb seems to be 10^6) it is 63.9Mb) or less doesn't give any errors, loading a file bigger then that gives the following error:
java.sql.SQLRecoverableException: Io exception: Software caused connection abort: socket write error
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:458)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:960)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:3856)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
at jdbctest.Tester.main(Tester.java:60)A succesful insert of a 63Mb file takes about 23 seconds to execute. The 70Mb file fails already after a few seconds, so I'm ruling out any time outs.
I'm guessing there are some buffers that need to be enlarged, but don't have a clue which ones.
Anyone any idea what might cause the problem and how to resolve?
My server runs Oracle 11g Win32. The client is Windows running Sun Java 1.6, using ojdbc6.jar and Oracle 11g Client installed.
Cheers,
HaraldHi Mark,
The trace log in the OEM shows me:
Errors in file d:\oracle11g\app\helium\diag\rdbms\helium\helium\trace\helium_ora_6948.trc (incident=7510): ORA-07445: exception encountered: core dump [__intel_new_memcpy()+613] [ACCESS_VIOLATION] [ADDR:0x0] [PC:0x6104B045] [UNABLE_TO_WRITE] [] If needed I can post the full contents (if I find out how, am still a novice :-))
Cheers,
Harald
Maybe you are looking for
-
During the syncing process my IPOD Nano 3G shows that the music files that I'm synching are registering as audio, and that the video files are registering as video, and even upon completion they are still labeled as such. But, when I eject the devic
-
New bought MSI AG240 2PE (non touch) all in one game pc working well
MSI AG240 2PE (non touch) all in one game pc working well. But its monitor's on screen display settings unreachable now from monitor's buttons. When İ first started the pc they were working normal. But a few hours later only working button was moni
-
Absolutely don't know what to do
One day, our second computer could not connect to the internet but it was connected to the network with the correct IP. I spent over an hour on the phone and nothing was found so it was in to the Apple Store for a reinstall of the OS. Computer connec
-
i am working on a project and i'm having a split screen. i've done the split screen with (crop and scale) on FCP but after i do that the video seems to have fuzzy edges. i've noticed on my external viewing monitor. what do i do to clean up the edges
-
Displaying calculated data in JSP pages
This is a general question about displaying data in JSP pages which has been calculated through ViewObj Routines. I have exposed the methods to the application level however, I want these methods to automatically run on the launch of the page. I can