• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in inserting Date feild

Kashif Iqbal Khan
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using MS SQL server database with jdbc odbc bridge driver. I have a table with the name of "student" have the feild of "DOB" having type of datetime and other feilds are of type of varchar etc. When i go for inserting the entries with DOB it give exception as follows:
"Microsoft][ODBC SQL Server Driver]Optional feature not implemented"
And when i go for inserting without DOB it goes perfectly.
I m using setDate(), setString() methods to parse the data according to sql type.
My code is as follows:
public void insertStudent(Student std){
try {
String query = new String("INSERT INTO student (RollNo, Name,DOB )VALUES(?,?,?)" );
PreparedStatement st= db.prepareStatement(query);
st.setDate(3,std.dob );
int rowsUpdated = st.executeUpdate();
Can any tell me the solution of this exception.
Mark Spritzler
Posts: 17309
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not directly answering your question. But in my Visual Basic code to write to Oracle, I take a Date, and make it a String. Then I call the to_date function in Oracle to convert the string to a date in the insert statement.
So in your example the insert statement would look like this.
INSERT INTO student (RollNo, Name,DOB )VALUES ("RollNO", "Name", to_date("03/29/03","MM/DD/YY")
now I know SQL Server has a conversion function to make strings into dates and the other way around. In Foxpro it was CTOD() which stands for "Character To Date".
So you could go down that route.
Good Luck
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!