OpenCms - Example Code To Show Oracle Query

You can access the database from within your JSP pages via java.sql.* (be sure to import java.sql.*, org.opencms.db.*, and org.opencms.main.* for it to work). Be sure to release the connection when you are done with it, in any case within the jsp, where you have opened it.

OpenCms's Database connection. (source: www.opencms-wiki.org)



<%@page import="java.sql.*,org.opencms.db.*,org.opencms.main.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<% java.sql.Connection con = OpenCms.getSqlManager().getConnection("default");
    Statement stmt = con.createStatement();
    ResultSet rs;
    rs = stmt.executeQuery("SELECT INITCAP(airlines) AS maskapai,TO_CHAR(dep_time, 'HH24:MI') AS departure,TO_CHAR(arr_time, 'HH24:MI') AS arrive,economi_rate FROM cms_flightdetails where ROWNUM <= 8");
%>


<div class="col-sm-12" style="padding:0">

 <div class="top-title">Berangkat</div>

 

 <div class="table-container">

  <div class="table-heading">

   <div class="table-column col-checkbox"></div>

   <div class="table-column col-icon"></div>

   <div class="table-column"><div class="col-middle-pos-airline"><div onclick="location.href='isidata.html';" class="thumb-arrow-up col-icon-align"></div><div onclick="location.href='isidata.html';" class="thumb-arrow-down col-icon-align"></div></div><a href="/lehaleha/sites/default/agen/big/flight/isidata.html">maskapai</a></div>

   <div class="table-column"><div class="col-middle-pos-departure"><div onclick="location.href='isidata.html';" class="thumb-arrow-up col-icon-align"></div><div onclick="location.href='isidata.html';" class="thumb-arrow-down col-icon-align"></div></div><a href="/lehaleha/sites/default/agen/big/flight/isidata.html">berangkat</a></div>

   <div class="table-column"><div class="col-middle-pos-arrived"><div onclick="location.href='isidata.html';" class="thumb-arrow-up col-icon-align"></div><div onclick="location.href='isidata.html';" class="thumb-arrow-down col-icon-align"></div></div><a href="/lehaleha/sites/default/agen/big/flight/isidata.html">tiba</a></div>

   <div class="table-column"><div class="col-middle-pos-price"><div onclick="location.href='isidata.html';" class="thumb-arrow-up col-icon-align"></div><div onclick="location.href='isidata.html';" class="thumb-arrow-down col-icon-align"></div></div><a href="/lehaleha/sites/default/agen/big/flight/isidata.html">harga</a></div>

  </div>

    

<%
    while (rs.next()) {
%>

  <div class="table-rows" style="margin-top: 15px;">

   <div class="table-column"><label class="checkbox large-checkbox"><input type="checkbox" id="lion-air-1" value="lion-air" /><span class='check'></span></label></div>

   <div class="table-column" id="thumb-icon-1"><div class="thumb-small-sriwijaya col-icon-center"></div></div>

   <div class="table-column" id="airline-1"><%= rs.getString("maskapai") %></div>

   <div class="table-column" id="departure-1"><%= rs.getString("departure") %></div>

   <div class="table-column" id="arrived-1"><%= rs.getString("arrive") %></div>

   <div class="table-column" id="ticket-price-1">Rp<span style="font-size: 25px;"><%= rs.getString("economi_rate") %></span></div>

  </div>

  

<%
   }
%>
  

 </div>

</div>

  

<%
    rs.close();
    stmt.close();
    con.close();
%>

SHARE

About Agung Pambudi

I am a Blogger with passion in business.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment