Solved

Date's related issues.

Posted on 2003-11-27
6
244 Views
Last Modified: 2010-04-01
Dear all,
i have this code. What i intended to do is get the user's date, dd/MM/yyyy and based on this user's entried date, i wish to retrieve all the data in the same month with it...
this is my code... but doesn't work with the date. Don't know how to convert here and there..... please correct me.

String month=request.getParameter("month");
SimpleDateFormat sf = new SimpleDateFormat("MM");
String mth= sf.format(month);

Connection conn=null;
ResultSet rs=null;
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   conn = DriverManager.getConnection("jdbc:odbc:myDSN");
  PreparedStatement ps = conn.prepareStatement( "SELECT * FROM PURCHASE WHERE Date = ?");
  rs= ps.executeQuery();

while (rs.next()) {
out.println("Date" + rs.getString("Date"));
}


errorr... lot of error...
0
Comment
Question by:acl6804
  • 4
6 Comments
 
LVL 1

Accepted Solution

by:
yapsing earned 250 total points
Comment Utility
i think your sql should be:
PreparedStatement ps = conn.prepareStatement( "SELECT * FROM PURCHASE WHERE Date = "+mth);

0
 
LVL 1

Expert Comment

by:yapsing
Comment Utility
r u using Oracle, Access or MySQL???
0
 
LVL 1

Expert Comment

by:yapsing
Comment Utility
to select data using the month in MySQL
PreparedStatement ps = conn.prepareStatement( "SELECT * FROM PURCHASE WHERE month(date) ="+mth);
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Expert Comment

by:kotakinabalu
Comment Utility
yapsing, i am using access.
but event i couldnt getthe month from the incoming date entry...
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
HI
The data field Date on your purchase table is a DATE or a VARCHAR?
if is a date you must transform if from the string, but also if you are receiving just the month not the full date you should do something to it either, if is a VARCHAR well then I guess you just have to put this sentence before the ExecuteQuery:
ps.setString(1,month);
I also saw that this sentence
String month=request.getParameter("month");
should be
String month=(String) request.getParameter("month");
and you shouls check if it gets null becose maybe it cames as an attibute then you shold do this
String month=(String)request.getParameter("month");
if(month==null)
    month=(String) request.getAttirbute("month");
if(month==null){
    System.out.println("Error moth is NULL");
    return the error to the client.
}else{
keep working
}

If the date is well fixed you should make this sentence before the ExecuteQuery
ps.setDate(1,mth);

Hope it helps
Javier


0
 
LVL 1

Expert Comment

by:yapsing
Comment Utility
i think he accepted the wrong answer. mine can't be the solution
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now