• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems when getting TIMESTAMPTZ data from Oracle database in JSP

 
Jake Lee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a column in the oracle table, its data type is TIMESTAMPTZ; I want to display it in the tabular form in JSP but got error like conversion to timestamp failed...
if you have come across something like this and have some code sample, please let me know, thanks a lot...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you could show us the detail of the error and the conversion code you are using.
 
Jake Lee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the error:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 35 in the jsp file: /iforacle.jsp
Generated servlet error:
C:\Apache\tomcat\work\Catalina\localhost\TomcatTest\org\apache\jsp\iforacle_jsp.java:130: cannot resolve symbol
symbol : method getTIMESTAMPTZ (int)
location: interface java.sql.ResultSet
out.print(rs.getTIMESTAMPTZ(2));
^
1 error
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

And the code:
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

String url = "jdbc racle:thin:@localhost:1521 B";
String user = "user";
String password = "password";

Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select * from Error";
ResultSet rs = stmt.executeQuery(sql);
%>
<table>
<tr>
<td>col1</td>
<td>col2</td>
</tr>
<% while(rs.next()) {%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getTIMESTAMPTZ(2)%></td>
</tr>
</table>

The first column is varchar2 and the second is TIMESTAMPTZ
I tried it with OracleResultSet but didn't work for me:

An error occurred at line: 13 in the jsp file: /iforacle.jsp
Generated servlet error:
C:\Apache\tomcat\work\Catalina\localhost\TomcatTest\org\apache\jsp\iforacle_jsp.java:104: incompatible types
found : java.sql.Connection
required: oracle.jdbc.driver.OracleConnection
OracleConnection conn = DriverManager.getConnection(url, user, password);
^
An error occurred at line: 13 in the jsp file: /iforacle.jsp
Generated servlet error:
C:\Apache\tomcat\work\Catalina\localhost\TomcatTest\org\apache\jsp\iforacle_jsp.java:105: incompatible types
found : java.sql.Statement
required: oracle.jdbc.driver.OracleStatement
OracleStatement stmt = conn.createStatement(OracleResultSet.TYPE_SCROLL_SENSITIVE, OracleResultSet.CONCUR_UPDATABLE);
^
An error occurred at line: 13 in the jsp file: /iforacle.jsp
Generated servlet error:
C:\Apache\tomcat\work\Catalina\localhost\TomcatTest\org\apache\jsp\iforacle_jsp.java:107: incompatible types
found : java.sql.ResultSet
required: oracle.jdbc.driver.OracleResultSet
OracleResultSet rs = stmt.executeQuery(sql);
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has nothing to do with date formatting. You need an import statement to define the java.sql classes you are using.

And I would be remiss if I did not point out that it is considered a horrible practice to perform SQL in a JSP page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!