Oracle Combat Day III-transaction processing and function ___ static functions

Source: Internet
Author: User
Tags rowcount stmt

Describes how the Java program operates Oracle Operations data Oracle Transaction SQL function usage in Oracle

Expected Goal: Master Oracle table on data manipulation skills. Mastering Oracle Operations in Java programs. Understand Oracle transactional concepts. Master various SQL functions for Oracle.

Java Connection Oracle

We've been working with Oracle in Pl/sql, so how do we manipulate databases in Java programs?

Here's an example: page displays user information for the EMP table

testoracle.jsp

<%@ page language= "java" import= "java.util.*,java.sql.*" pageencoding= "Utf-8"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

<title>oracle Page Case </title>

<meta http-equiv= "Pragma" content= "No-cache" >

<meta http-equiv= "Cache-control" content= "No-cache" >

<body>

<table>

<tr>

<td> Employee Name </td>

<td> Salary </td>

</tr>

<%

Query Total Pages

int pagecount = 0;

There are a total of several records

int rowcount = 0;

Show several records per page

int pageSize = 3;

Receive the current number of pages

String Strpagenow = Request.getparameter ("Pagenow");

int pagenow = 1;

if (strpagenow!=null)

{

Pagenow = integer.valueof (Strpagenow);

}

Connection conn = null;

Statement stmt = null;

Try

{

Load Driver

Class.forName ("Oracle.jdbc.driver.OracleDriver");

Get Connected

conn = Drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "Scott", "Tiger");

stmt = Conn.createstatement ();

ResultSet rs= stmt.executequery ("SELECT count (*) from EMP");

while (Rs.next ())

{

RowCount = Rs.getint (1);

if (rowcount%pagesize = 0)

{

PageCount = rowcount/pagesize;

}

Else

{

PageCount = rowcount/pagesize + 1;

}

}

rs = Stmt.executequery ("SELECT *" (select T.*,rownum rn from (SELECT * from emp) t where rownum <= "+ pagenow*pages Ize + ") where RN >=" + ((pageNow-1) *pagesize + 1) + "");

while (Rs.next ())

{

Out.print ("<tr>");

Out.print ("<td>" +rs.getstring (2) + "</td>");

Out.print ("<td>" +rs.getint (6) + "</td>");

Out.print ("</tr>");

}

Out.print ("<tr>");

for (int i =1; i<=pagecount; i++)

{

Out.print ("<a href=" testoracle.jsp?pagenow= "+i+" ">[" +i+ "]</a>");

}

Out.print ("</tr>");

}

catch (Exception e)

{

throw new RuntimeException (e);

}

Finally

{

Try

{

if (stmt!= null)

{

Stmt.close ();

}

IF (conn!= null)

{

Conn.close ();

}

}

catch (Exception ex)

{

throw new RuntimeException (ex);

}

}

%>

</table>

</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.