*
The moose likes JDBC and the fly likes Retreiving data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retreiving data " Watch "Retreiving data " New topic
Author

Retreiving data

Beena Thomas
Greenhorn

Joined: Sep 26, 2001
Posts: 5
import java.sql.*;
import java.text.*;
import java.util.*;
String instr,startMonth,startDate,startYear,endMonth,endDate,endYear,sDate,eDate;

instr=request.getParameter("instruments");
startMonth=request.getParameter("startMonth");
startDate=request.getParameter("startDate");
startYear=request.getParameter("startYear");
endMonth=request.getParameter("startMonth");
endDate=request.getParameter("startDate");
endYear=request.getParameter("startYear");
sDate=startMonth+"/"+startDate+"/"+startYear;
eDate=endMonth+"/"+endDate+"/"+endYear;


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:myDatabase");
Statement stmt=con.createStatement();
String query ="SELECT Grantor,Grantee,Location FROM Retrieval WHERE File_Date Between sDate And eDate ";

ResultSet rs=stmt.executeQuery(query);

while(rs.next())
{
String grantor=rs.getString("Grantor");
String grantee=rs.getString("Grantee");
String location=rs.getString("Location");
}
con.close();
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

nice code.
Jamie
[This message has been edited by Jamie Robertson (edited November 28, 2001).]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

what is the data type of File_Date in the database? if it is a date field and you are using an access database, then try

The way you had your query set up, it was not substituting values for sDate and eDate.
Jamie
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

you could also use a PreparedStatement;

If anyone knows a more natural way to convert the dates post it...I'm not too familiar with manipulating dates
I like using PreparedStatements where possible. Seems to be less problems further down the road.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retreiving data
 
Similar Threads
Retreiving data
While Loop in Gantt Chart values
Calendar class
Passing objects to different methods
Pass a String array from a jsp to a servlet