my dog learned polymorphism*
The moose likes JDBC and the fly likes Problem in inserting Date feild Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in inserting Date feild" Watch "Problem in inserting Date feild" New topic

Problem in inserting Date feild

Kashif Iqbal Khan

Joined: Dec 22, 2001
Posts: 13
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.

Kashif I. Khan
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

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

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Consider Paul's rocket mass heater.
subject: Problem in inserting Date feild
Similar Threads
Oracle date-time fields
JDBC Newbie
exception while connecting sqlserver 2000 with java application
Regarding database connectivity in servlets
[Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt