• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Inserting nulls

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Java Gurus,
The question may soud dumb but ...let me ask. I have a varchar column and in my program I have a string variable that take sdata from thr textbox in the gui and inserts it into database. My problem is if th evalue in text box is empty then it is entering empty string into database. I want it to enter nothing.....I canno tchange any database setting and database I am using is Sql server.
Thanks,
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gayathri,
If you are using a "java.sql.PreparedStatement" to insert the data into your database, then you can use the "setNull()" method to set a column value to null -- assuming that you want to set the column to null if nothing has been entered into the "textbox".
I suggest you read the javadoc for the "setNull()" method.
Hope this helps.
Good Luck,
Avi.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using PreparedStatement then you may try this.
PreparedStatement ps=null;
...
...
if(textString == null)
{
ps.setNull(1, java.sql.Types.VARCHAR);
}
else
{
ps.setString(1,textString);
}
Suresh Selvaraj
 
Beware the other head of science - it bites! Nibble on this message:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic