Cant Get Date Inside MSSQL Server DB

Discussions

Web tier: servlets, JSP, Web frameworks: Cant Get Date Inside MSSQL Server DB

  1. Cant Get Date Inside MSSQL Server DB (4 messages)

    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);
  2. 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; }
  3. Yes !One MOre Way For Oracle[ Go to top ]

    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
  4. Yes !One MOre Way For Oracle[ Go to top ]

    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
  5. HOW TO: SQL in JAVA[ Go to top ]

    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.

    Shahriar Nour Khondokar