Problem with date | Member | | Join Date: Sep 2007
Posts: 37
| |
Hi .. friends.. in the below program -
public void actionPerformed(ActionEvent ae)
-
{
-
int flag=0;
-
s1=(from.getText());
-
s2=(to.getText());
-
if(ae.getSource()==view)
-
{
-
-
-
try
-
{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
con=DriverManager.getConnection("jdbc:odbc:prism");
-
stmt=con.createStatement();
-
stmt1=con.createStatement();
-
-
rs=stmt.executeQuery("select SUM(NOSRECEIVED),SUM(REJPCS) from Visual where DATE BETWEEN '"+s1+"' AND '"+s2+"' ");
-
rs1=stmt1.executeQuery("select SUM(D1),SUM(D2),SUM(D3),SUM(D4),SUM(D5),SUM(D6),SUM(D7),SUM(D8),SUM(D9),SUM(D10),SUM(D11),SUM(D12),SUM(D13) FROM Rej where DATE BETWEEN'"+s1+"'AND '"+s2+"'");
-
-
-
-
}
-
-
where s1,s2 are String Data Types
in the above program i got the sql error as Data type mismatch criteria.. i know that the problem is with data types..can u say wat kind of data type i have to declare to solve this problem...
Thanking you....
Regards
Pradeep
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Problem with date Quote:
Originally Posted by pradeep84 Hi .. friends.. in the below program -
public void actionPerformed(ActionEvent ae)
-
{
-
int flag=0;
-
s1=(from.getText());
-
s2=(to.getText());
-
if(ae.getSource()==view)
-
{
-
-
-
try
-
{
-
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
con=DriverManager.getConnection("jdbc:odbc:prism");
-
stmt=con.createStatement();
-
stmt1=con.createStatement();
-
-
rs=stmt.executeQuery("select SUM(NOSRECEIVED),SUM(REJPCS) from Visual where DATE BETWEEN '"+s1+"' AND '"+s2+"' ");
-
rs1=stmt1.executeQuery("select SUM(D1),SUM(D2),SUM(D3),SUM(D4),SUM(D5),SUM(D6),SUM(D7),SUM(D8),SUM(D9),SUM(D10),SUM(D11),SUM(D12),SUM(D13) FROM Rej where DATE BETWEEN'"+s1+"'AND '"+s2+"'");
-
-
-
-
}
-
-
where s1,s2 are String Data Types
in the above program i got the sql error as Data type mismatch criteria.. i know that the problem is with data types..can u say wat kind of data type i have to declare to solve this problem...
Thanking you....
Regards
Pradeep What database are you using? Checks its specs for a to_date(it could be called something else depending on the database you are using) function that converts characters to dates.
|  | Moderator | | Join Date: Dec 2007 Location: Kelowna, BC Canada
Posts: 1,212
| | | re: Problem with date Quote:
Originally Posted by r035198x What database are you using? Checks its specs for a to_date(it could be called something else depending on the database you are using) function that converts characters to dates. No, it's still preferable to use a PreparedStatement and let the driver worry about that. The resulting code will be more vendor-independent.
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: Problem with date Quote:
Originally Posted by BigDaddyLH No, it's still preferable to use a PreparedStatement and let the driver worry about that. .... I didn't dispute that. Using the PreparedStatement makes him convert the string to date in the code (which is a good idea) and then use setDate or setTimestamp. It won't automatically convert his strings to dates for camparisions with the database values.
|  | Moderator | | Join Date: Dec 2007 Location: Kelowna, BC Canada
Posts: 1,212
| | | re: Problem with date Quote:
Originally Posted by r035198x I didn't dispute that. Using the PreparedStatement makes him convert the string to date in the code (which is a good idea) and then use setDate or setTimestamp. It won't automatically convert his strings to dates for camparisions with the database values. I agree. He should be working with a Date object, not a string. That calls for SimpleDateFormat, if starting from a string: http://java.sun.com/javase/6/docs/ap...ateFormat.html |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|