• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String lentgh problem in java-oracle

 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
I am facing a very strange problem.
I made a simple program which connects to databse and return the lentgh of String.
but length of String is comming wrong.........

below is my java code also output of console is pasted.

I am using classes12.zip to connect with oracle,and I have tried varios version of classes12.zip but result is same

Oracle Server is running on Solaris 9 and Oracle version is 9.1.0.4

My java program is runing on win 2000 professional.

anyone please suggest







/*************** Output *******************/

########### output With resulset ###########
value of @strMode1 is >> E
lenght of @strMode1 is >> 32
lenght of @strMode1 after trim is >> 1
value of rs.getString is >>E
and lenght is >>32
value of rs.getString is >>E and lenght is >>32
Press any key to continue . .
[ October 28, 2004: Message edited by: Shailesh Chandra ]
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here we haven't define any size for the column MODET. we are just using dual. So what i think, the default type of dual is CHAR not VARCHAR or VARCHAR2 and the default length is 32 character. therefore you are getting this result. but after trim it works fine. just try one more system.out.

System.out.println(rs.getString(1)+"?");

then see whether the question mark is the second character in the printed string or 33rd character.
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also Tried same but result is same !!!
see the last line of java code ...that is doing same.
also I have done same with code once you mentioned
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No suggestions just trim it and use it. thats why we have this trim() method in String class.

ok what are you getting if query some other table like, emp.

select ename from emp;

try this out.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using StringBuffer instead String... may help :-)
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Hardik,

my problem is with length of String that is retrieved from Database.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
select ename from emp

then get back to us. i wanna know the results of this query. thanx
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seelct emp name from emp works fine.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, the problem sounds like the same. see my first reply to this post. not sure but a intelligent guess.
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may as you replied very first.

my core problem is that I have one commoan API to exectue all query in my application.

every thing is fine but some times I appends blank space and makes string lentgh 32.

to narraow the problem I made a java program which was beahving same.

so I want to get core reason why I am facing this problem.

however I have used trim to solve problem 2 days back.

but still looking for an answer
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



but still looking for an answer



Dear friends after searching various site !!!

I have solved this problem.

This problem is because of a DataBase parameter named as cursor_sharing


when I issued command my problem got solved

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the value of cusor_sharing before? and why it was not applied to emp table?

anyways, good to here it worked after a long time.
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by adeel ansari:
What is the value of cusor_sharing before? and why it was not applied to emp table?



Value of cursor_sharing was SIMILAR !!!

however I identified the problem
as every thing was working good at one of my client.
but when some optimisation were madethen we started getting same problem
which I was getting at my different client.

after comparing DB parameter we found parameter

cursor_sharing is changed to FORCED from EXACT.

then at my this client I checked the same paramteer

SELECT * FROM V$PARAMETER WHERE NAME ='cursor_sharing'

and value was similar at my end.

hope this will help to those who will face similar kind of problem.

problem was with SELECT 'E' From dual kind of query

not with select emp from emptable


i got one article on
Ask TOM


thanks....
[ October 29, 2004: Message edited by: Shailesh Chandra ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic