File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in inserting Date feild" Watch "Problem in inserting Date feild" New topic
Author

Problem in inserting Date feild

Kashif Iqbal Khan
Greenhorn

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.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.


Kashif I. Khan
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in inserting Date feild