error - help pls

I am getting the following error when i try to run my program. The program is just logging into a database and retrieving some records.I have a login method(to load the database) and a query method that queries the database and gets some records.

the query method is something like this

code:

--

/** * This method queries the database for the given query * @param query the query String */

void query(String query,String updatestr,String query1) { ResultSet rs,rs1;

try {Statement stat = connection.createStatement();

rs = stat.executeQuery(query);

while (rs.next()) {

String s = rs.getString("status");

if( s.equals("Complete") ){

System.out.println("ERROR:movie_id ALREADY

RETURNED");

}

else {

stat.executeUpdate

(updatestr);

rs1 = stat.executeQuery(query1);

while(rs1.next()) {

int n = rs1.getInt("movie_id");

String str2 = rs1.getString("ReturnDate");

System.out.println("movie_id is" + n);

System.out.println("returnDate"+str1);

}// while

} // else

} // while rs.next()

} // try

catch (Exception e) {

e.printStackTrace();

}

}

--

My main method passes query strings to the query method.

Main Method

code:

--

public static void main(String[] args) {

if (args[1] == null) {

System.err.println("Username not present");System.exit(1);

}

if(args[3] == null) {

System.err.println("Password not given");System.exit(1);

}

Banniinsertch banni = new Banniinsertch(args[1], args[3]);

try {

System.out.println(" enter command");

BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

String str = keyboard.readLine();

StringTokenizer st = new StringTokenizer(str);

while (st.hasMoreTokens()) {

int i,c =st.countTokens();

String snk[] = new String[c];

for(i=0;i<c;i++) {

snk=st.nextToken();

System.out.println(snk);

}

String updatestr = "UPDATE rental SETstatus='Complete'"+

"WHERE movie_id ="+ snk[1] + "AND return_date="+ snk[2]+ "AND status="+ "'Active'";

String query1 = "SELECT movie_id,to_char(return_date,'Month

DD,YYYY')"+"AS ReturnDate FROM rental"

+"WHERE movie_id ="+ snk[1]+"AND return_date ="+ snk[2];

String check = "SELECT status FROM rental"+

" WHERE movie_id ="+ snk[1];

banni.query(check,updatestr,query1);

}

} catch (IOException e) {

System.out.println("error : " + e);

}

banni.close();

}

--

I dont know why I am getting the following error.

java.sql.SQLException: ORA-00904: "MAR": invalid identifier

at java.lang.Throwable.fillInStackTrace(Native Method)

at java.lang.Throwable.fillInStackTrace(Compiled Code)

at java.lang.Throwable.><init>(Compiled Code)

at java.lang.Exception.<init>(Exception.java:42)

at java.sql.SQLException.<init>(SQLException.java:43)

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)

at oracle.jdbc.ttc7.TTIoer.processError(Compiled Code)

at oracle.jdbc.ttc7.Oall7.receive(Compiled Code)

at oracle.jdbc.ttc7.TTC7Protocol.doOall7(Compiled Code)

at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)

at oracle.jdbc.driver.OracleStatement.executeNonQuery(Compiled Code)

at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)

at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)

at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:796)

at Banniinsertch.query(Compiled Code)

at Banniinsertch.main(Compiled Code)

My inputs are movie_id (121212145) and return_date (20-MAR-02)

When i try to run the query at the SQL prompt it works!!!

I am new to jdbc, so can anyone pls tell whats causing these errors and how to correct it. I would really appreciate if any one can help me as this is urgent!!

thanks

sagarika

[4237 byte] By [sagarika1] at [2007-9-27 22:36:31]
# 1

String updatestr = "UPDATE rental SET status='Complete'"+

"WHERE movie_id ="+ snk[1] + "AND return_date="+ snk[2]+ "AND status="+ "'Active'";

Should be something like this

String updatestr = "UPDATE rental SET status='Complete'"+

"WHERE movie_id ="+ snk[1] + "AND to_char(return_date,'MM/DD/YYYY') = '" + snk[2]+ "' AND status="+ "'Active'";

You'll have to substitute whatever date format.

You can tell that the update failed when you read the stack trace, and see the "executeUpdate" call.

mcalm01 at 2007-7-7 13:22:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

three things.

1) it does not like having the text MAR instead of a number in your date

i think.

2) Jet SQL (what you use through ODBC) is not entirely the same as the

SQL you use in Access

3) one of the differences is that your should for date values in ODBC

wrap them with a # symbol instead of quotes

a further comment on differences between Jet and staight Access is that

for wildcard searches with LIKE the Jet wildcard is % and the Access one

is *. i'm not sure why these are different it is certainly a pain for

testing but it is what it is.

mcalm01 at 2007-7-7 13:22:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Thanks mcalm01 and scsi-boy a lot showing my mistake.-sagarika
sagarika1 at 2007-7-7 13:22:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...