-
Cant Get Date Inside MSSQL Server DB (4 messages)
- Posted by: Kumaran Naidu
- Posted on: March 12 2007 09:28 EDT
My problem is , getting the Date Value inside the MSSQL server Db,using Servlets. Even I tried Converting Dates in java.sql.Date Format,used SimpleDateFormat,Even Converted it to Timetamp as MSSQL Server takes Dates In as TimeStamp Format. Still The Error "Syntax error converting datetime from character string." cmoing on Tomcat Logs. Sample Code .. String doi=req.getParameter("doi"); //Date Conversion Style 1 /*java.util.Date today = new java.util.Date();//creating date java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");//format definition java.sql.Date d = java.sql.Date.valueOf(sdf.format(today));//creating SQL Date. pw.println(today + "XXX\n " + d);*/ //Date Conversion Style 2 /*SimpleDateFormat formater = new SimpleDateFormat("yyyy-mm-dd"); java.util.Date parsedDate = formater.parse(doi); java.sql.Date result = new java.sql.Date(parsedDate.getTime());*/ try{ DateFormat df = new SimpleDateFormat( "MM-dd-yyyy" ); Timestamp d = new Timestamp( df.parse(doi).getTime() ); } DateFormat df = new SimpleDateFormat( "MM-dd-yyyy" ); Timestamp d = new Timestamp( df.parse(doi).getTime() ); //ps.setDate(5,d); ps.setTimestamp(5,d);Threaded Messages (4)
- Re: Cant Get Date Inside MSSQL Server DB by sruthi Mandalika on March 20 2007 02:56 EDT
- Yes !One MOre Way For Oracle by Kumaran Naidu on March 27 2007 09:27 EDT
- Yes !One MOre Way For Oracle by Kumaran Naidu on March 27 2007 09:27 EDT
- HOW TO: SQL in JAVA by shahriar khondokar on July 06 2010 08:56 EDT
-
Re: Cant Get Date Inside MSSQL Server DB[ Go to top ]
- Posted by: sruthi Mandalika
- Posted on: March 20 2007 02:56 EDT
- in response to Kumaran Naidu
Hey, I am also doing something similar.I have datetime as datatype in database and I am using this function to convert any valid date in string. public static String convertDate(String date) { ParsePosition p1=new ParsePosition(0); String format=null; DateFormat dateFormat=null; SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy"); java.util.Date d1=null; try{ d1=df.parse(date,p1); }catch(Exception e){ System.out.println("date"+e); } dateFormat = new SimpleDateFormat("MM/dd/yyyy"); String date1=dateFormat.format(d1); return date1; } -
Yes !One MOre Way For Oracle[ Go to top ]
- Posted by: Kumaran Naidu
- Posted on: March 27 2007 09:27 EDT
- in response to sruthi Mandalika
What U Had Posted will Work..but i m working on Oracle so even after converting to valid format i m geeting error..so opted for "to_char,to_date & to_timestamp" functions of oracle ,still in the process so hopefully will get it. Thanks 4 Replying, regards Kumaran -
Yes !One MOre Way For Oracle[ Go to top ]
- Posted by: Kumaran Naidu
- Posted on: March 27 2007 09:27 EDT
- in response to sruthi Mandalika
What U Had Posted will Work..but i m shifted my work on Oracle so even after converting to valid format i m geeting error..so opted for "to_char,to_date & to_timestamp" functions of oracle ,still in the process so hopefully will get it. Thanks 4 Replying, regards Kumaran -
HOW TO: SQL in JAVA[ Go to top ]
- Posted by: shahriar khondokar
- Posted on: July 06 2010 08:56 EDT
- in response to Kumaran Naidu
Check this article HOW TO: SQL in JAVA for details on how to connect to SQL Server database from Java database applications. It also describes how to pass embedded SQL queries (SELECT, INSERT, UPDATE, DELETE), calling stored procedures, pass parameters etc.
Here you will also find information on how the Java and SQLServer data types map.