The Artima Developer Community
Sponsored Link

Java Answers Forum
Help..

2 replies on 1 page. Most recent reply: Jul 6, 2004 1:43 AM by Nick

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Nick

Posts: 9
Nickname: nicolashad
Registered: Jul, 2004

Help.. Posted: Jul 5, 2004 6:13 AM
Reply to this message Reply
Advertisement
hi!
someone might help me to correct this code's part.I'll would take the date of system (i think it's called "now")and compare that with an other date (just present in data base that i created ). And if the date is before of "now", it's all right, if the date is after "now" i'll would that in the database appare "N" near the item selected.
I write down this code:


<jsp:include page="include/defineConnection.jsp"/>
<% java.sql.Connection conn = java.sql.DriverManager.getConnection((String) request.getAttribute("DBConnection"), "", "");
java.sql.PreparedStatement ps = conn.prepareStatement("select * from percorsi");
java.sql.ResultSet rs = ps.executeQuery();
while (rs.next()) {
String id = (String) rs.getString(1);
java.util.Date data = (java.util.Date) rs.getDate(5);
String[] ids = java.util.TimeZone.getAvailableIDs(+1 * 60 * 60 * 1000);
java.util.SimpleTimeZone pdt = new java.util.SimpleTimeZone(+1 * 60 * 60 * 1000, ids[0]);
java.util.Calendar cal = new java.util.GregorianCalendar(pdt);
//java.util.Date today = cal.get(java.util.Calendar.DATE);
int d = cal.get(java.util.Calendar.DAY_OF_MONTH);
int m = cal.get(java.util.Calendar.MONTH);
int y = cal.get(java.util.Calendar.YEAR);
String oggi = d + "/" + m + "/" + "y";
java.util.Date today = java.sql.Date.valueOf(oggi);
/*if (E.before(today) == true) {*/if (data.before(today)) {
java.sql.PreparedStatement ps2 = conn.prepareStatement("update percorsi set stato = ? where id_percorso = ?");
ps2.setString(1, "N");
ps2.setString(2, id);
int result2 = ps2.executeUpdate();
ps2.close();
}}
rs.close();
ps.close();
conn.close();%>

Thanks


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Help.. Posted: Jul 5, 2004 12:23 PM
Reply to this message Reply
From your code it looks like you have a table with a date field and a state field (I guess you call it stato in your code). You want to set state fields to N if the date field contains future date. If this is all you are trying to accomplish then instead of retrieving all data to JSP and then updating the record one by one, you can issue one update statement to your Database. Use a statement like this.

update your_table_name
set state = 'N'
where your_date_column > the_function_to_get_today_date;

Note that, the_function_to_get_today_date depends on your database. If you are using Oracle then it will be sysdate. If you are not able to figure out the function name for your database that returns current date then let us know about your database name and someone will help you.

Thanks
Kishori

Nick

Posts: 9
Nickname: nicolashad
Registered: Jul, 2004

Re: Help.. Posted: Jul 6, 2004 1:43 AM
Reply to this message Reply
Thank. I use Access how DB

Flat View: This topic has 2 replies on 1 page
Topic: Concurrent Singleton usage - Limitations ? Previous Topic   Next Topic Topic: SWT and OS features

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use