Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes JDBC and Relational Databases 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

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "finding the closest time in database record" Watch "finding the closest time in database record" New topic

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 + " ";
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

Joined: May 26, 2003
Posts: 31668

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,

[OCA 8 book] [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

Joined: Jan 10, 2002
Posts: 62292

Jeanne is correct. Moving to JDBC.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Have you tried LearnNowOnline?
subject: finding the closest time in database record