lilanw
asked on
Select statement
please correct this statement... this is not working,,,,
Statement statement;
ResultSet resultset;
try
{
query = "SELECT FlightNumber FROM FlightD where Date = '" + _date +"'" && `From = "'" + _from +"'" && To ="'" + _to + "'" ;
statement = connect.createStatement();
resultset = statement.executeQuery(que ry);
statement.close();
}
catch(SQLException sqlex){sqlex.printStackTra ce();}
Statement statement;
ResultSet resultset;
try
{
query = "SELECT FlightNumber FROM FlightD where Date = '" + _date +"'" && `From = "'" + _from +"'" && To ="'" + _to + "'" ;
statement = connect.createStatement();
resultset = statement.executeQuery(que
statement.close();
}
catch(SQLException sqlex){sqlex.printStackTra
could you please give me the variable declaration and value for date,from,to
query = "SELECT FlightNumber FROM FlightD where Date = _date
&& `From = " + _from +" && To =" + _to + " " ;
date should be java.sql.date variable
try this for date.
String possibleValidDate ="something";
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM- dd");
sdf.setLenient(false);
Date d = sdf.parse(possibleValidDat e);
}
catch(Exception e) {
System.err.println("Invali d date " + possibleValidDate);
}
&& `From = " + _from +" && To =" + _to + " " ;
date should be java.sql.date variable
try this for date.
String possibleValidDate ="something";
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-
sdf.setLenient(false);
Date d = sdf.parse(possibleValidDat
}
catch(Exception e) {
System.err.println("Invali
}
query = "SELECT FlightNumber FROM FlightD where Date = " + _date + " AND From = " + _from + " AND To = " + _to;
Using a PreparedStatement would make the statement cleaner, be easier to code and proof the code against variable date formats, thus making the code more portable too
A little tutorial for PreparedStatement.
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
Here's a little tutorial about the different SQL statements you might find useful
http://www.stardeveloper.com/articles/display.html?article=2002030801&page=1
http://www.stardeveloper.com/articles/display.html?article=2002030801&page=1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> it is a reserved word and should not be use as a column.
actually, you can. however you must delimit it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_03_6e9e.asp
so your query would be,
query = "SELECT FlightNumber FROM FlightD where Date = " + _date + " AND [From] = " + _from + " AND To = " + _to;
actually, you can. however you must delimit it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_03_6e9e.asp
so your query would be,
query = "SELECT FlightNumber FROM FlightD where Date = " + _date + " AND [From] = " + _from + " AND To = " + _to;
ok, I get it now,
From and To are places names, not dates, my mistake oops
-Muj
From and To are places names, not dates, my mistake oops
-Muj
No prob.