• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

gettind date from the oracle table!

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers..

I'm doing a project in jsp oracle..
in the.. i 've created an example.. table..
the description of the table is shown below!!
_______________________________________
datein DATE
name VARCHAR(10)
_______________________________________

this is the description.. of table

now... i've used the insert query to insert the date in to the table..
and it is inserted properly.. in the format 'dd/mmm/yyyy'

and there is no problem..

now when i start retreving the table records..
it is displaying the date in another format..
it is in 'yyyy-mm-dd'

so it is quiet difficult for me to search according to the date.. i don't know what to do with that..

ranchers.. please help me..



 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aravind use TO_CHAR function of Oracle.
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The confusion is that date storage and date representation are different things. If you select a date from the database using a ResultSet you can just treat it as a java.sql.Date (or Time or Timestamp) object and use a date formatter to make it whatever format you want. Otherwise you will get behaviour that shifts with the locale in ways you maybe didn't expect.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ranchers..

I can run the query if i give the query using the to_char

but in my program it is not working

the query is this
select to_char(datein,'dd-mmm-yyyy') from ff order by datein;

it is working in sql prompt..

but it is not working in jsp page..

_________________________________________________________________________
my code is here
______________________________________________________________________
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>DETAILS</title>
</head>
<%@ page language="java" session="true" import="java.sql.*" import= "java.lang.*" %>

<body>
<table border =1 width = "100%">
<tr>
<td> Date in</td>
<td> Name </td>
</tr>

<%

try
{
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{out.println(e);
}

String dbURL = "jdbc dbc:test";


Connection dbCon;
dbCon = DriverManager.getConnection(dbURL,"aravindprasad","2356296");

StringBuffer tab1 = new StringBuffer();

tab1.append("select to_char(datein,'dd-mm-yy') from ff");



String query = tab1.toString();
out.println(query);

Statement stmt = dbCon.createStatement();
ResultSet rs = stmt.executeQuery(query);
// declaring the variables

while(rs.next())
{
//Date datein = rs.getDate(1);
//String name = rs.getString(2);
Date datein = rs.getDate(1);
%>
<tr>
<td><a href ="check.jsp?datein=<%=datein%>">
<%=datein%> </a> </td>


</tr>

<%
}
rs.close();
dbCon.close();
stmt.close();
%>



</table>

<%
//stmt.close();
}
catch(SQLException e)
{//response.sendRedirect("error.html");
out.println(e);

}
%>

</body>

</html>
___________________________________________________________________
i think the code has to work properly
but it is showing the error like this

java.sql.SQLException: [Oracle][ODBC]Datetime field overflow.
____________________________________________________________________

can u pls help me.. to solve this problem..

thanks in advance
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double check the types when you call rs.getXXX(). to_char returns a String type.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic