aspose file tools*
The moose likes JDBC and the fly likes finding the closest time in database record Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "finding the closest time in database record" Watch "finding the closest time in database record" New topic
Author

finding the closest time in database record

Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
I am implementing a small registration process using JSP and mysql. I am stuck with how to implement a unregister functionally. My question are:
1. Do I use datetime type in database? (in the following mydate is a datetime type.) I have tried the following and it's not working.
<jsp:useBean class="com.minter.db.ConnectionManager" id="CM" scope="session" />
<%@ page import ="java.util.*"%>
<%@ page import="java.sql.*" %>
<% java.util.Date u_day = new java.util.Date();
String timestamp = "INSERT INTO TEST (mydate) VALUES " + u_day + " ";
CM.executeUpdate(timestamp);
%>
2. Once a user unregister, I would like to find the record of closest time to this one and change the status from waiting list to enrol. How could I do it efficiently? If I read all record from db into JSP and then find the record, it seems like too complex a solution.
Thank you.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

This is more of a JDBC question.
1) The format of u_day needs to match the format that your database is using. (you may want to consider using a prepared statement so you don't have to worry about details like these) Also, you are missing some punctuation. The syntax is:

2) You can try to do this with two queries, one to find the closest record before and one to find the closest record after. For example,


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Jeanne is correct. Moving to JDBC.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding the closest time in database record