java and oracle

java and oracle

hai i am doing a project in which i have stored some data (think as 50 records) in database. Now i want to retrive the data from the database(20 records at each time but should be different for each time)..........
please help me for this..............
View Answers

March 11, 2010 at 10:50 AM

Hi Friend,

We have used Mysql for this purpose. Try the following code:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%!
public int nullIntconvert(String str){
int num=0;
if(str==null) {
str="0";
}
else if((str.trim()).equals("null")) {
str="0";
}
else if(str.equals("")) {
str="0";
}
try{
num=Integer.parseInt(str);
}
catch(Exception e) { }
return num;
}
%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;

int showRows=20;
int totalRecords=20;
int totalRows=nullIntconvert(request.getParameter("totalRows"));
int totalPages=nullIntconvert(request.getParameter("totalPages"));
int iPageNo=nullIntconvert(request.getParameter("iPageNo"));
int cPageNo=nullIntconvert(request.getParameter("cPageNo"));

int startResult=0;
int endResult=0;
if(iPageNo==0) {
iPageNo=0;
}
else{
iPageNo=Math.abs((iPageNo-1)*showRows);
}
String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();

String query2="SELECT FOUND_ROWS() as cnt";
ps2=conn.prepareStatement(query2);
rs2=ps2.executeQuery();
if(rs2.next()) {
totalRows=rs2.getInt("cnt");
}
%>
<html>
<h3>Pagination of JSP page</h3>
<body>
<form>
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="showRows" value="<%=showRows%>">
<table width="100%" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Marks</td>
<td>Grade</td>
</tr>
<%
while(rs1.next()){
%>
<tr>
<td><%=rs1.getInt("rollNo")%></td>
<td><%=rs1.getString("name")%></td>
<td><%=rs1.getInt("marks")%></td>
<td><%=rs1.getString("grade")%></td>
</tr>
<%
}
%>
<%
try{
if(totalRows<(iPageNo+showRows)) {
endResult=totalRows;
}
else{
endResult=(iPageNo+showRows);
}
startResult=(iPageNo+1);
totalPages=((int)(Math.ceil((double)totalRows/showRows)));
}
catch(Exception e){
e.printStackTrace();
}
%>
<tr>
<td colspan="3">
<div>

March 11, 2010 at 10:51 AM

continue....

<%
int i=0;
int cPage=0;
if(totalRows!=0) {
cPage=((int)(Math.ceil((double)endResult/(totalRecords*showRows))));

int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
if((cPage*totalRecords)-(totalRecords)>0){
%>
<a href="pagination.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="pagination.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%> - <%=endResult%> Total Rows <%=totalRows%> </b>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
try{
if(ps1!=null){
ps1.close();
}
if(rs1!=null){
rs1.close();
}

if(ps2!=null){
ps2.close();
}
if(rs2!=null){
rs2.close();
}

if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
java-oracle
java-oracle  hi friends, I wanted to upload a image from jsp page to oracle database.i am not getting how to do it... Please help me if you can....... please give me detail code
Oracle - Java Beginners
Oracle   Hi sir, I installed oracle but the error occur on The java Runtime Environment was not found, at bin\jrew.exe. Hence the Oracle Universal Installer can not be run JRE version 1.1.7 Are the Java and Oracle related
Advertisements
JAVA BEAN WITH ORACLE FORMS
JAVA BEAN WITH ORACLE FORMS  Hi..I am doing my final year Project.. I need the ste-by-step procedure to integrate a bean with oracle forms? Please help me
java to oracle code - JDBC
java to oracle code  please suggest m calculate the database performance between scaled images and unscaled images in the database
java with Oracle Database
java with Oracle Database  Hello I have been encountering a problem regarding creating a table with Oracle.When i am creating new table in the Database using Oracle , it is giving error saying an errror occured incursive sql
java and oracle - JSP-Servlet
java and oracle  I am developing a small project where I need to upload the resume of the employee and store it into database and retrieve the same... data types in oracle database. And I need to write the code in servlets
Java Connection to Oracle database
Java Connection to Oracle database  HI I am ubable to connnect jdbc to Oracle database.i had gone to control panel >>Administrative tool>>>Data source,in that forDNS name i typed Oracle and in TNS i culdn't
java connecting to oracle db
java connecting to oracle db  PLZ SAY ME HOW TO INSERT THE VALUES INTO ORACLE THIS IS THE CODE: import java.io.*; import java.sql.*; import..."); Connection con=DriverManager.getConnection("jdbc:oracle:thin
oracle
oracle   sir now am doing one project , my frond end is vb and backend is oracle. so 1> how can i store the image in my field 2> how can i back up the table into .txt file
Java vs Oracle Connectivity - JDBC
Java vs Oracle Connectivity  Write a java program to establish connection with oracle database?  Hi Friend, Use Oracle with Java Follow these steps: 1) Import the following packages in your java file
java connecting to oracle db - JDBC
java connecting to oracle db  how to connect oracle data base with java application?  Hi Friend, Follow these steps: 1) Import the following packages in your java file:*********** import java.sql.*; import
java and oracle - JSP-Servlet
java and oracle  hai i am doing a project in which i have stored some data (think as 50 records) in database. Now i want to retrive the data from the database(20 records at each time but should be different for each time
Java Barcode Program with Oracle database
Java Barcode Program with Oracle database  Hi Everyone, I need help... no and serial no of the item being scanned to Oracle 10g database. I dont have any idea abt this...Please can anyone give me some idea. Do I need to buy Java
ex. connect to Oracle - Java Beginners
ex. connect to Oracle  dear sir, I want to ask how to connect java to oracle, please give me a details tutorial with example code how to connect to oracle. what software i must to use? thank's   Hi
java oracle connection problem - SQL
java oracle connection problem  I have successfully made connection with the oracle10g database that i am using and also able to put in data using JSP. But the codes that i have tried for fetching the data are not working even
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle... Panel>>Administrative Tools>>Data Sources in that i selected Oracle... just typed DNS as Oracle and for TNS i clicked on the list of TNS. But it has
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle... Panel>>Administrative Tools>>Data Sources in that i selected Oracle... just typed DNS as Oracle and for TNS i clicked on the list of TNS .But it has
About connection database oracle to java
About connection database oracle to java  **Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
Oracle Certified Java Programmer Assistance
Oracle Certified Java Programmer Assistance  Hi all I wanted to know that I have recently completed my graduation and heading towards Post Graduation. I wanted to know that if I pass the OCJP certification will it be useful after
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
Installing oracle Java 8 on Ubuntu 18.04
Installing oracle Java 8 on Ubuntu 18.04  Hi, What are the steps for installing oracle java 8 on ubuntu 18.04? I want to install Oracle Java 8... the Oracle Java JDK 8 in Ubuntu 18.04. Here are the steps to install Oracle Java 8
i need latest oracle certified java dumps.. Pleas help me?
i need latest oracle certified java dumps.. Pleas help me?  i need latest oracle certified java dumps.. Pleas help me
Convert the excel sheet data into oracle table through java or jsp
Convert the excel sheet data into oracle table through java or jsp  Hi Friends, Let me help this issue i am phasing Convert the excel sheet data into oracle table through java or jsp
Exception while inserting image in oracle using java
Exception while inserting image in oracle using java  import...()); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost... affected: "+stmt.executeUpdate()); } } My Oracle table description is: create table
Oracle Books
Oracle Books         Building Oracle XML Applications This rich and detailed look at the many Oracle tools that support XML development shows Java
Oracle Launches Project Valhalla for Java
Oracle Launches Project Valhalla for Java with an aim to evolve new features..., the Oracle have announced its much awaited Project Valhalla for Java. Certainly a long... of project Java by Oracle, now it has open an experimental OpenJDK project
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two... am using the oracle. please help. thankyou sir
oracle - SQL
oracle  can you suggest me a book regarding oracle and java even..  Hi friend, For more information on Oracle and Java Books visit to : http://www.roseindia.net/programming/books/Freejavabooks.shtml http
How to Install Oracle Java JDK 8 in Ubuntu 16.04?
How to Install Oracle Java JDK 8 in Ubuntu 16.04?  Hi, Let's know the commands to install Oracle Java 8 on Ubuntu 16.04. How I can install Oracle Java 8? How to Install Oracle Java JDK 8 in Ubuntu 16.04? Thanks   Hi
Oracle - JDBC
Oracle fetch variables  i wanted to fetch variables from database using Oracle
Oracle - SQL
Oracle  Oracle Begginers , if Downloadable Notes are there Please mention the site
oracle 18/04/2013
oracle 18/04/2013   Why it is called as structured query language
Oracle BLOB
Oracle BLOB  Can anyone send me the code for inserting an image or audio into the oracle database using BLOB datatype. Plz...it's useful for my project
java script unable to connect to oracle database and insert data
java script unable to connect to oracle database and insert data  ... is to insert data from jsp to oracle database 8, so i create a table in oracle... jsp coding in rose india for sql and i changed the drivers for oracle.. when i try
Maven dependency for us.fatehi - schemacrawler-oracle version 16.12.2 is released. Learn to use schemacrawler-oracle version 16.12.2 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.12.2 in Java projects. Follow... - schemacrawler-oracle version 16.12.2 java library in your project. Now you can...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.14.2 is released. Learn to use schemacrawler-oracle version 16.14.2 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.14.2 in Java projects. Follow... - schemacrawler-oracle version 16.14.2 java library in your project. Now you can...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.14.5 is released. Learn to use schemacrawler-oracle version 16.14.5 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.14.5 in Java projects. Follow... - schemacrawler-oracle version 16.14.5 java library in your project. Now you can...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.15.2 is released. Learn to use schemacrawler-oracle version 16.15.2 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.15.2 in Java projects. Follow... - schemacrawler-oracle version 16.15.2 java library in your project. Now you can...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.16.14 is released. Learn to use schemacrawler-oracle version 16.16.14 in Maven based Java projects
to use  us.fatehi - schemacrawler-oracle version 16.16.14 in Java projects. Follow... and includes  us.fatehi - schemacrawler-oracle version 16.16.14 java library in your...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.19.3 is released. Learn to use schemacrawler-oracle version 16.19.3 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.19.3 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.19.3 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.19.2 is released. Learn to use schemacrawler-oracle version 16.19.2 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.19.2 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.19.2 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.19.2 is released. Learn to use schemacrawler-oracle version 16.19.2 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.19.2 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.19.2 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.19.1 is released. Learn to use schemacrawler-oracle version 16.19.1 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.19.1 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.19.1 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 14.02.02 is released. Learn to use schemacrawler-oracle version 14.02.02 in Maven based Java projects
to use  us.fatehi - schemacrawler-oracle version 14.02.02 in Java projects. Follow... and includes  us.fatehi - schemacrawler-oracle version 14.02.02 java library in your...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.16.12 is released. Learn to use schemacrawler-oracle version 16.16.12 in Maven based Java projects
to use  us.fatehi - schemacrawler-oracle version 16.16.12 in Java projects. Follow... and includes  us.fatehi - schemacrawler-oracle version 16.16.12 java library in your...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.16.9 is released. Learn to use schemacrawler-oracle version 16.16.9 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.16.9 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.16.9 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.16.8 is released. Learn to use schemacrawler-oracle version 16.16.8 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.16.8 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.16.8 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle
Maven dependency for us.fatehi - schemacrawler-oracle version 16.16.7 is released. Learn to use schemacrawler-oracle version 16.16.7 in Maven based Java projects
; us.fatehi - schemacrawler-oracle version 16.16.7 in Java projects. Follow...; us.fatehi - schemacrawler-oracle version 16.16.7 java library in your project...-oracle released The developers of   us.fatehi - schemacrawler-oracle

Ads