Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / May 2007

Tip: Looking for answers? Try searching our database.

jdbc connection to Sybase

Thread view: 
Wayne Happ - 24 May 2007 16:56 GMT
Hi

I have an application that's sending the below SQL to a Sybase
database. Version 12.5

---
  String proc is set to

exec p_setPERunType  1, 'CorpMarks', "set rowcount 100
select distinct symbol = rtrim(y.symbol) from yieldcurve y where
pe_run_type = 1 and exists(select * from yieldcurvecomponent yc where
y.symbol = yc.symbol) and exists(select * from gridpointhist h where
y.symbol = h.symbol) and industrycode != 'AG'", 'outfile.data', null,
'PECorpMarks', 'update', 'vladimirn', ''

Then I call

Statement deststmt = dest.createStatement();
               deststmt.execute(proc);

---
The result is an error message that says

SQL Exception generated. The identifier that starts with '"set
rowcount 100
select dis' is too long. Maximum length is 28.

I'm new to JDBC, there's nothing wrong with the SQL itself, when I cut
and paste it into an isql session it executes just fine. Is there some
parameter Inbeed to set to make JDBC take the whole thing?

As a side note, I'm not the author of the SQL.
joeNOSPAM@BEA.com - 24 May 2007 18:54 GMT
Hi. The trouble is the double-quotes you're using to delineate the
long string parameter. The ISQL client will interpret that, but
JDBC just sends the string as-is. Better to use all single-quotes,
and escape the ones inside the big string. I believe the escape is
to just have an immediate second single-quote:

"exec p_setPERunType  1, 'CorpMarks', 'set rowcount 100
select distinct symbol = rtrim(y.symbol) from yieldcurve y where
pe_run_type = 1 and exists(select * from yieldcurvecomponent yc where
y.symbol = yc.symbol) and exists(select * from gridpointhist h where
y.symbol = h.symbol) and industrycode != ''AG''', 'outfile.data',
null,
'PECorpMarks', 'update', 'vladimirn', ''"

However, the good JDBC style for running stored procedures
would be with a PreparedStatement and parameters:

String jdbc_sql = "{ call setPERunType( ?, ?, ?, ?, ?, ?, ?, ?, ? )}";
PreparedStatement p = c.prepareStatement(jdbc_sql);
p.setInt(1, 1);
p.setString(2, "CorpMarks");

String big_arg = "set rowcount 100 select distinct symbol =
rtrim(y.symbol) from yieldcurve y where "
+ "pe_run_type = 1 and exists(select * from yieldcurvecomponent yc
where y.symbol = yc.symbol) and "
+ "exists(select * from gridpointhist h where y.symbol = h.symbol) and
industrycode != 'AG'";

p.setString(3, big_arg );
p.setString(4, "outfile.data");
p.setObject(5, null);
p.setString(6, "PECorpMarks");
p.setString(7, "update");
p.setstring(8, "vladimirn");
p.setString(9, "");

p.execute();

Joe Weinstein at BEA Systems


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.