Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet java and oracle
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


praveen kumar reddy.y
java and oracle
2 Answer(s)      4 years and 7 months ago
Posted in : JSP-Servlet


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..............

Advertisement
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 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
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 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 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
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
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
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
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
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
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 Books
Oracle Books         Building Oracle XML Applications This rich and detailed look at the many Oracle tools that support XML development shows Java
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
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
Oracle invites Community to Weigh-In on Java EE8
Oracle invites Community to Weigh-In on Java EE8 - Take part in survey... Edition, Java EE 8. Oracle has invited the enterprise development community... its tradition of community collaboration and its advantages, Oracle has once
Oracle - JDBC
Oracle fetch variables  i wanted to fetch variables from database using Oracle
Advertisements
 

 

 

DMCA.com