7 Replies Latest reply: Nov 28, 2006 5:22 AM by 800322 RSS

    Inserting a GregorianCalendar into a SQL Server datetime column.

    807607
      I'm trying to do everything, but nothing seems to work :(

      Here the code:
                  GregorianCalendar datetime = parseStringToDate(datetimestring);
                  java.sql.Timestamp sqlTime = new java.sql.Timestamp(datetime.getTimeInMillis());
                  
                  try {
                      Statement stmt = conn.createStatement();
                      ResultSet rs;
                      String query = "INSERT INTO myTable (colString, myTime) VALUES ('" + aString + "', " + sqlTime + ")";
                      System.out.println(query);
                      rs = stmt.executeQuery(query);
                  } catch (SQLException sqle) {
                      System.out.println(sqle);
                  }
      here the output:
      INSERT INTO myTable (colString, myTime) VALUES ('hello world', 2006-11-28 09:17:50.0)
      java.sql.SQLException: Sintassi non corretta in prossimit� di '09'.
      The last error means something like: "Not correct syntax near '09'"

      I also tried to single-quote the datetime value.. but without result :(