aspose file tools*
The moose likes JDBC and the fly likes String lentgh problem in java-oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "String lentgh problem in java-oracle" Watch "String lentgh problem in java-oracle" New topic
Author

String lentgh problem in java-oracle

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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 ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 13, 2004
Posts: 1081

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

Joined: Aug 15, 2004
Posts: 2874
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.
Hardik Pathak
Greenhorn

Joined: Sep 23, 2004
Posts: 2
Try using StringBuffer instead String... may help :-)
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Dear Hardik,

my problem is with length of String that is retrieved from Database.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
try
select ename from emp

then get back to us. i wanna know the results of this query. thanx
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

seelct emp name from emp works fine.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
So, the problem sounds like the same. see my first reply to this post. not sure but a intelligent guess.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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

Joined: Aug 13, 2004
Posts: 1081



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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 13, 2004
Posts: 1081

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String lentgh problem in java-oracle