• 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

Inserting junk values while using Prepared Statement

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am using oracle 8.1.7 and oracle 9i jdbc driver.I am inserting multiple records using prepared statement.I gave auto commit false and i am iterating each record and setting value using prepared statement and calling execute update.Finally after the end of the loop i am doing commit and made setAutoCommit(true).But it is inserting junk values for a particular column in the database. The code is given below

Regards
Vasu
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you insert the right data into a field. If there is a function which database uses before inserting data into a field, you need to call that function in your sql statement. For instance, "insert into customer(id,name) values (HEXTORAW(?),?)" where HEXTORAW is the function that database uses to convert a hex number to a raw number before inserting the record.
 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No i didnt use any function
 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Someone help me to solve this problem.
Regards
Vasu
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vasu,
Can you post the SQL you are using?
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is this all true:
1. the first column with a ? in your PreparedStatement is a char or varchar (or some similar text-based) dataype into which you can safely insert a constant string? In other words, if you change your SQL (strsql) to replace the first ? with a constant value (such as 'hello world'), and then comment out your first pst.setXXX() and renumber the rest, do you get that fixed string value inserted reliably?
2. ut.trim(i.getIssueTitle()) returns a String. (although here you ought to get the same behavior of an automatic toString() within the pst.setString() method call as you get in the System.out.println() call....)
3. The string you're trying to insert has no control characters in it (backspaces, etc.) - if you're on UNIX, redirect the System.out.println to a file and then use "od -c <filename>". On PC, try to open it in a dumb editor that doesn't handle special characters well.... Windows notepad should show little squares or something.
4. Assuming #1, the string you're trying to insert is small enough to fit in the column specified (not 'Hello World' into varchar(3) or something similar)
5. The 9i JDBC driver says it's compatible with the 8.1.7 DB Server? (I might check this first...)
If all of those are true, check the release notes for the JDBC driver, see if there's a known issues list online, search Google Groups....
And, yes, pls post the SQL, and possibly the table structure - that'd help.
Good luck,
Jon Egan
 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jon,

Thanks for suggestion but i already tried all the things before posting the qusetion in forum. I hardcoded some value in prepared statement but still it inserts some junk values into table. As i said earlier i even tried printing the value i am passing it and it returns the correct value. Problem is that prepared statement is not setting the correct value. I am facing similar type of problem in more than one screens in my project.Intresting thing is that prepared statement for same table is working perfectly for insert statements but it is not working for update statements.

Regards
Vasu
 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Any body knows about this problem...
Regards
Vasu
 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me on this problem...
Regards
Vasu
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vasu,
Can you post the SQL you are using? More information would help in providing you a more detailed response.
 
Vasudevan Gopalan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jeanne,
This is the update query i am using .

Regards
Vasu
 
reply
    Bookmark Topic Watch Topic
  • New Topic