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?
THanks
right, 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.
Similar Messages
-
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 filevignesh_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. -
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, -
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 -
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 -
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. -
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 -
Hi,
I have a problem with connecting flat files(.txt, .xml, .csv, .xls, etc...) which is existing in application it's self, using jdbc connection.
After searching I found some suggestions below.
1)xlsql
2)JDO
I tried with first one (xlsql), below is the process. First create core java project and load the jar files which is from xlsql. below is the code
Class.forName("com.nilostep.xlsql.jdbc.xlDriver");
final String dir = System.getProperty("user.dir")+"\\db\\xl";
conn = DriverManager.getConnection("jdbc:nilostep:excel:/"+dir);
Statement stmt = con.createStatement();
String sql = "select * from Sheet1$";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
System.out.println(rs.getString(1));
}else{
System.out.println("nodata....");
It is saying Sheet1$ table not existing.
Please help me.Not quite sure of your definition of a flat file, but a .xls files is a Microsoft Excel workbook, which is saved in a proprietary binary format, so there's certainly nothing 'flat' about it. Of course, there are odbc and suchlike drivers for treating Excel workbooks as data sources, but you need to ensure when you query them that you know the details of the workbook.
In each workbook, each spreadsheet has a name (as defined on it's tab at the bottom). That is taken to be the name of the 'table' that you use when you query it with SQL.
On each spreadsheet, row 1 of that sheet should denote the column names of the 'table'
All subsequent rows on the spreadsheet are the data that will be returned from querying it.
Typically, the data on the sheets should be fairly straightforward, in order to query it. Some excel functionality may prevent it being queried properly. -
Error while loading xml files using JDBC
Hi,
I am trying to load xml files into an xmltype table using JDBC calls and am getting this error for some files
LPX-00200: could not convert from encoding UTF-8 to UCS2
The xml files and our database are both UTF-8 encoded. The version of oracle that we have here is 9.2.0.6
Any suggestions in this matter will be greatly appreciated.
Thanks,
UmaI also experienced this problem and unfortunately this solution didn't work for me given that the tag you suggested was already on the XML file.
-
Upload .Sql file using sqlloader
Hi ,
Having a sql file
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9818764535,9899875643,'IN',to_date('2013-05-24 02:10:43','YYYY-MM-DD HH24:MI:SS') ,10) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9899453215,9215478213,'OUT',to_date('2013-05-24 08:11:13','YYYY-MM-DD HH24:MI:SS') ,20) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9999050217,9899875643,'IN',to_date('2013-05-25 18:07:02','YYYY-MM-DD HH24:MI:SS') ,30) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9818764535,9012451785,'IN',to_date('2013-05-26 02:11:13','YYYY-MM-DD HH24:MI:SS') ,40) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9818764535,9215478213,'IN',to_date('2013-05-26 08:17:02','YYYY-MM-DD HH24:MI:SS') ,25) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9818764535,9899875643,'OUT',to_date('2013-05-26 20:21:04','YYYY-MM-DD HH24:MI:SS') ,67) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9818764535,9899875643,'IN',to_date('2012-05-25 22:07:02','YYYY-MM-DD HH24:MI:SS') ,30) ;
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID" ,9818764535,9899875643,'IN',to_date('2013-05-25 22:07:02','YYYY-MM-DD HH24:MI:SS') ,30) ;
Loading this using sql loader (sqlldr)
Plz helpyes i am mapping the columns and it is inserting whole
insert into dpcdr.CALLID ("ID" ,MOBILE_NUMBER ,OTHER_PARTY ,CALL_TYPE ,CALL_DATE_TIME ,DURATION )
Values (:"ID"
into my first column
How to skip or exclude this? -
How to access PL/SQL code using JDBC
Hi,
We have stored procedures written in PL/SQL. These stored procs take both IN and OUT parameters. The parameter types are both regular datatypes like NUMBER, VARCHAR etc. So far so good. I know how to handle these data types.
Some of the stored procs also use parameters that are defined as composite data types like %ROWTYPE or %RECORD. How would I set the values of these data types? Can I use the oracle extension - support for Oracle Objects to accomplish this. If so please let me know with an example. If not any other suggestions or help will be greatly appreciated.
Thanks
KarthikJDBC (and SQLJ) only support SQL types as stored procedure arguments, not PL/SQL types.
If your stored procedure uses a PL/SQL-only type, such as BOOLEAN, record types, or index-by tables, then you cannot call it from Java (or, for that matter, from other languages as well).
There is one exception: scalar index-by table arguments have been supported since JDBC 8.1.7 in the JDBC-OCI driver (refer to the JDBC manual for specifics).
One workaround is to create wrapper PL/SQL stored procedures that take SQL arguments and convert them to PL/SQL -and vice versa- and call the original PL/SQL stored procedures. For example, a record type could be exploded into individual arguments, or it could be converted into a SQL object type, index-by tables could be represented as SQL collection types, etc.
You can find a small example of this in the back of the JPublisher manual, where an example is given how to call a PL/SQL stored procedure that takes BOOLEAN arguments. -
Calling a procedure in postgresql using JDBC
Hai,
I am using POSTGRESQL 8.0.3 and Java 1.5.
I wrote a follwing procedure in POSTGRESQL. When I tried to call this procedure using JAVA I am getting the following exception.
Exception in thread "main" java.sql.SQLException: ERROR: syntax error at or near "$1"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1471)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1256)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:175)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:389)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:330)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:240)
at ShowSurabhi2.main(ShowSurabhi2.java:44)Code Snippet to call the procedure
Class.forName("org.postgresql.Driver");
dbcon = DriverManager.getConnection(loginUrl, loginUser, loginPasswd);
CallableStatement cs=dbcon.prepareCall("{call proc1()}");
cs.execute();
ResultSet rs = (ResultSet)cs.getObject(1);
// Iterate through each row of rs
while (rs.next())
id = rs.getInt(1);
name=rs.getString(2);
}Procedure in POSTGRESQL named, proc1
declare tt numeric;
begin
select max(id) into tt from test
tt = tt + 1;
ret tt;
end;Regards
ackumarAh, there's a bug in your pgsql, I think. Here's the amended sproc I was using:
create or replace function testSproc()
returns numeric
as
declare tt numeric;
begin
select max(id) into tt from test;
tt = tt + 1;
return tt;
end
language 'plpgsql';Note that it's "return tt", not "ret tt"
Here's my test table and data:
create table test (
id integer
insert into test (id) values (1);
insert into test (id) values (2);
insert into test (id) values (3);
insert into test (id) values (4);
insert into test (id) values (5);I didn't try it with your code, which I suspect is wrong - it seems to presume a result set is being returned - but the following works as-is against my database. Obviously change the url/username/password for your scenario.
import java.sql.*;
public class Sproc {
public static void main(String[] args)
throws Exception
String loginUrl = "jdbc:postgresql:junit";
String loginUser = "junit";
String loginPasswd = "junit";
Class.forName("org.postgresql.Driver");
Connection dbcon = DriverManager.getConnection(loginUrl, loginUser, loginPasswd);
CallableStatement cs= dbcon.prepareCall("{call testSproc()}");
ResultSet rs = cs.executeQuery();
while(rs.next()) {
System.out.println(rs.getInt(1));
} -
How to read accdb and mdb files using JDBC or File Adapter
Hi,
How to read and extract the .accdb and .mdb files from FTP server and parsing into xml by using FTP or JDBC Adapter in SAP PI7.11 With linx Os.
Regards
UpendraHi,
As per SAP note:1681420 i have to install the below driver from Microsoft
Our SAP PI installed under Unxi OS ,how to install the driver (.exe file) .
Driver name :AccessDatabaseEngine_x64.exe
Url:Download Microsoft Access Database Engine 2010 Redistributable from Official Microsoft Download Center
1681420 - PI : Where to locate the JDBC Driver for Microsoft Access
Regards
Upendra
Maybe you are looking for
-
Unable to clear vendor with different currency being posted
Dear Experts, One of our vendor's Invoice billed in currency USD, several payments has been posted with different currency according to our Bank currencies. Full payment has been made to the balance of ZERO, but we still unable to clear this vendor a
-
Can't import songs from music library to itunes!
I have no problems importing songs from audio cds into itunes, but it won't recognize any of the files that i have in other folders of my computers (in mp3 format). and when i select 'import' and these songs, it just doesn't do anything. any suggesti
-
Using wildcards in PreparedStatement
Hi, i have had a look about the forum, and found a few answers but they seem to relate to MSSQL not MySQL. I am using a PreparedStatement sql = "SELECT * FROM table WHERE postcode LIKE '%?%' "; PreparedStatement psmt = connection.prepar
-
I have a problem with my refurbished fifth generation video iPod. When I plug my earphones in I can only get sound out of one earbud. I tried another pair of earphones but I had the same problem. Both pairs of earphones work fine with my PSP. I tried
-
Sidecar installation with Adobe AIR 1.5.3
Hi all, I'm having some difficulty with a sidecar installation with AIR 1.5.3. I've followed the steps in the runtime redistribution pdf (especially the section "Using the bundled runtime installer") but no luck yet. Here's my scenario: 1. Building t