Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in inserting Date feild

 
Kashif Iqbal Khan
Greenhorn
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.setString(1,std.rollNo);
st.setString(2,std.name);
st.setDate(3,std.dob );
int rowsUpdated = st.executeUpdate();
db.close();
}
Can any tell me the solution of this exception.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
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
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic