plz plz help me immediately(urgent required) How can i fetch a date dtatype from a database ??
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kumar_john
Posted On:   Sunday, October 28, 2007 02:39 AM

How can i fetch a date dtatype from a database ?? when i'm using the following command Date d1=rs.getDate("departuredate"); then i got error like this:- Exception in thread "main" java.sql.SQLException: Column not found at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(JdbcOdbcResultSet.java:185 0) at sun.jdbc.odbc.JdbcOdbcResultSet.getDate(JdbcOdbcResultSet.java:967) at test1.main(test1.java:18).. when i use this command :- select * from x where from ='bangalore' i got the following error:- Exception in thread "main" java.sql.SQLException: [IBM][CLI Driver][DB2/NT] SQL0 206N "   More>>

How can i fetch a date dtatype from a database ??

when i'm using the following command

Date d1=rs.getDate("departuredate");


then i got error like this:-
Exception in thread "main" java.sql.SQLException: Column not found
at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(JdbcOdbcResultSet.java:185
0)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDate(JdbcOdbcResultSet.java:967)
at test1.main(test1.java:18)..


when i use this command :-


select * from x where from ='bangalore'


i got the following error:-



Exception in thread "main" java.sql.SQLException: [IBM][CLI Driver][DB2/NT] SQL0
206N "DEPARTUREDATE" is not valid in the context where it is used. SQLSTATE=42
703
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:2
53)
at test1.main(test1.java:12)



so plz plz tell me how can i fetch date from database.

   <<Less

Re: plz plz help me immediately(urgent required) How can i fetch a date dtatype from a database ??

Posted By:   David_Thornton  
Posted On:   Monday, October 29, 2007 08:21 PM

You could try replacing;

Date d1=rs.getDate("departuredate");

with;

Date d1=rs.getDate(i);

where i is the column number of the column DEPARTUREDATE.


This statement;


select * from x where from ='bangalore'

should give you a syntax error "SQL0206N "FROM" is not valid in the context where it is used" as "FROM" is a reserved word in SQL and cannot be the name of a column.


You can verify the names of the columns in your table that the JDBC driver sees using code similar to this;


Class.forName([driver class name]);
Connection con = DriverManager.getConnection([connection url]);
DatabaseMetaData dbMetadata = con.getMetaData();
ResultSet columns = dbMetadata.getColumns(null, [schema name], [table name], null);
while (columns.next()) {
System.out.println(columns.getString(4));
}
con.close();

Re: plz plz help me immediately(urgent required) How can i fetch a date dtatype from a database ??

Posted By:   Stephen_McConnell  
Posted On:   Sunday, October 28, 2007 10:02 AM

The problem you are having is not fetching the Date datatype, the code you are using is correct. However, the exception you get "column not found" should be a clue. You are not using the correct column name.


Figure out the correct column name and you should get the correct value.


Stephen McConnell

About | Sitemap | Contact