Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 26th, 2008, 01:34 PM
a_n_n_a_m a_n_n_a_m is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 a_n_n_a_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 14 sec
Reputation Power: 0
Insert date

hello im kinda new to sql..

im using mckoi and i want to use an "insert into table values ('')" type command to insert a date into a date-datatype field..

im passing the value as a text string in the format yyyy-mm-dd.

i get the following error:
com.mckoi.database.jdbc.MSQLException: Unable to parse string as a date (yyyy-MM-dd)
com.mckoi.database.jdbcserver.AbstractJDBCDatabaseInterface.handleExecuteThrowable(AbstractJDBCDatab aseInterface.java:289)
com.mckoi.database.jdbcserver.AbstractJDBCDatabaseInterface.execQuery(AbstractJDBCDatabaseInterface. java:479)
com.mckoi.database.jdbcserver.JDBCDatabaseInterface.execQuery(JDBCDatabaseInterface.java:251)
com.mckoi.database.jdbc.MConnection.executeQuery(MConnection.java:453)
com.mckoi.database.jdbc.MConnection.executeQueries(MConnection.java:436)
com.mckoi.database.jdbc.MStatement.executeQueries(MStatement.java:193)
com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:167)
com.mckoi.database.jdbc.MPreparedStatement.executeUpdate(MPreparedStatement.java:203)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.ja va:102)
org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.doEndTag(UpdateTagSupport.java:157)
org.apache.jsp.tag.web.createCwk_tag._jspx_meth_sql_005fupdate_005f0(createCwk_tag.java:234)
org.apache.jsp.tag.web.createCwk_tag.doTag(createCwk_tag.java:157)
org.apache.jsp.admin.actions.createCwk_jsp._jspx_meth_anna_005fcreateCwk_005f0(createCwk_jsp.java:10 6)
org.apache.jsp.admin.actions.createCwk_jsp._jspService(createCwk_jsp.java:64)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
filters.getAttrFilter.doFilter(getAttrFilter.java:66)

.. so im guessing there is a special way of inserting dates that i dont know about? :/

any help will be greatly appreciated. tnx!

Reply With Quote
  #2  
Old April 26th, 2008, 05:17 PM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 7,675 Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level)Yawmark User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 2 Days 1 h 2 m 17 sec
Reputation Power: 1453
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
Quote:
so im guessing there is a special way of inserting dates that i dont know about?

Perhaps. It's more likely that you're just writing your code in a non-idiomatic way. Use a PreparedStatement and make sure you're using the correct data types. Beyond that, check the Mckoi documentation.

On a side note, I notice that the last release of Mckoi was August, 2004. You may want to consider using a more current RDBMS, such as Derby (included with Java 6), HSQLDB, or MySQL.

~
Comments on this post
lnxgeek agrees!
__________________
Yawmark
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

Reply With Quote
  #3  
Old April 27th, 2008, 10:41 AM
tvc3mye's Avatar
tvc3mye tvc3mye is offline
Daniel Schildsky
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: KL, Malaysia.
Posts: 566 tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 18 h 54 m 7 sec
Reputation Power: 154
Send a message via ICQ to tvc3mye Send a message via MSN to tvc3mye Send a message via Yahoo to tvc3mye
Alternative way to insert date type to DB

Try using the DATE function specified in SQL92 standard. It is recommended in the McKoi documentation.
__________________
When the programming world turns decent, the real world will turn upside down.

Reply With Quote
  #4  
Old April 27th, 2008, 10:54 AM
a_n_n_a_m a_n_n_a_m is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 a_n_n_a_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by Yawmark
Perhaps. It's more likely that you're just writing your code in a non-idiomatic way. Use a PreparedStatement and make sure you're using the correct data types. Beyond that, check the Mckoi documentation.

On a side note, I notice that the last release of Mckoi was August, 2004. You may want to consider using a more current RDBMS, such as Derby (included with Java 6), HSQLDB, or MySQL.

~


tnx for replying.. using mckoi was within my project specifications..

im doing this:
Code:
Date date = new Date(0000-00-00);
boolean fls = false;

PreparedStatement createCwk = conn.prepareStatement("INSERT INTO assignments VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
createCwk.setString(1, unit + "-" + year + "-" + assName); 
createCwk.setString(2, unit + "-" + year); 
createCwk.setString(3, assName); 
createCwk.setDate(4, date.valueOf(startDate));
createCwk.setDate(5, date.valueOf(endDate));
createCwk.setString(6, weighting); 
createCwk.setString(7, total); 
createCwk.setBoolean(8, fls); 
createCwk.executeUpdate();


and getting this error:

root cause

java.lang.IllegalArgumentException
java.sql.Date.valueOf(Date.java:103)

startDate and endDate are strings in the form yyyy-mm-dd

any ideas?

Reply With Quote
  #5  
Old April 27th, 2008, 10:58 AM
a_n_n_a_m a_n_n_a_m is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 a_n_n_a_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by tvc3mye
Try using the DATE function specified in SQL92 standard. It is recommended in the McKoi documentation.


im sorry.. ive been searching for hours with no luck..

how's the date function? where can i find its definition??

many tnx

Reply With Quote
  #6  
Old April 27th, 2008, 11:55 AM
stdunbar stdunbar is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 1,698 stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 12 h 27 m 54 sec
Reputation Power: 325
Send a message via ICQ to stdunbar Send a message via Yahoo to stdunbar
You'll need to parse the date out yourself. Take a look at SimpleDateFormat. You'll want to do something on the order of:

java Code:
Original - java Code
  1.  
  2. SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
  3.  
  4. ...
  5. createCwk.setDate(4, sdf.parse(startDate));
  6. createCwk.setDate(5, sdf.parse(endDate));
  7.  
  8. ...
Comments on this post
Yawmark agrees!
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Reply With Quote
  #7  
Old April 28th, 2008, 07:13 PM
a_n_n_a_m a_n_n_a_m is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 a_n_n_a_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 14 sec
Reputation Power: 0
tnx so much!! finally worked

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Insert date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway