Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Calendar object in JDBC
    text
    copied!<p>I'm using Netbeans and Derby database. I would like to insert to a table records with date field, so I was told to use <code>Calendar</code> object since it contains what I need: date (day, month and year), hour and minute.</p> <p>As you can see in the code below, the table field is of type <code>DATE</code>. When I try to insert the <code>Calendar</code> object as a String (with commas like in the code below), I get:</p> <blockquote> <p>The syntax of the string representation of a datetime value is incorrect.</p> </blockquote> <p>When I try to insert it without commas I get: </p> <blockquote> <p>Syntax error: Encountered "[" at line 1, column 159</p> </blockquote> <p>Probably something with the Calendar object. What am I missing here?</p> <pre><code>String from = fromForm.getText(); String to = toForm.getText(); String []date = dateForm.getText().split("/"); String []time = timeForm.getText().split(":"); int places = Integer.parseInt(placesForm.getText()); int closinghours=Integer.parseInt(closingHoursForm.getText()); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Integer.parseInt(date[2]),Integer.parseInt(date[1]),Integer.parseInt(date[0]),Integer.parseInt(time[0]),Integer.parseInt(time[1])); String query="INSERT INTO APP.TRUMPS (TRUMPID,DEPART,ARRIVE,START,PLACES,PROPOSING_USER_LOGIN,CLOSING_HOURS)"+ "VALUES ('"+newTrampTrumpistClient.login+dateForm.getText()+timeForm.getText()+"','"+from+"','"+to+ "','"+calendar+"',"+places+",'"+newTrampTrumpistClient.login+"',"+closinghours+")"; String result=newTrampTrumpistClient.WritingReading("sql_insert", query); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload