Share on Google+Share on Google+

Ragini Shukla
Helllllllllll
3 Answer(s)      8 years ago
Posted in : Java Beginners

Ads

View Answers

August 14, 2008 at 3:02 PM


Hi friend,

you do some changes

set per_page variable;

if u want set 20 record per page then

int per_page = 20;

"filename.jsp" change with the name of file u save the code.

<%@ page language="java" import="java.sql.*;"%>

<html>

<head>

<style>

A:hover {
text-decoration: none;

font-family:arial;

font-size:12px;

color: #000000;

BORDER: none;

}

A {
text-decoration: underline;

font-family:arial;

font-size:12px;

color: #000000;

BORDER: none;
}
</style>

</head>

<body>

<br><br><br>

<%

int offset=0;

int ofset = 0;

if(request.getParameter("offset")!=null)

{

offset= Integer.parseInt(request.getParameter("offset").toString());

}

int total_count = 0;

int total_page = 0;

int per_page =3;

String name="";

if(offset>1){

ofset = offset*per_page-per_page;

}





System.out.println("MySQL Connect Example.");

Connection conn = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;;
String db = "databasename";
String driver = "com.mysql.jdbc.Driver";
String userName ="";
String password="";

String color = "#F9EBB3";





try {

Class.forName(driver);
conn = DriverManager.getConnection(url+db,userName,password);



Statement stcount = conn.createStatement();

String strQuerycount = "select count(*) from tablename ";

ResultSet rscount = stcount.executeQuery(strQuerycount);

if(rscount.next())

{

total_count=rscount.getInt(1);

}



if(total_count%per_page==0)

{

total_page = total_count/per_page;

}

else

{

total_page = total_count/per_page+1;

}


Statement st = conn.createStatement();

String strQuery = "select * from tablename limit "+ofset+","+per_page;

// out.println(strQuery);



ResultSet rs = st.executeQuery(strQuery);

// out.println("offset " + offset);

int count=0;

if(offset>1)

count=offset*per_page-per_page;





%>



<br><br><br>

<table width="900px" align="center" style="border:1px solid #000000;" >

<tr>

<td colspan=8 align="center" style="background-color:ffeeff"><b>Transaction Report</b></td>

</tr>

<tr style="background-color:efefef;">

<td><b>SNo</b></td>

<td><b>Field 1</b></td>
<td><b>Field 2</b></td>
<td><b>Field 3</b></td>
<td><b>Field 4</b></td>

</tr>


August 14, 2008 at 3:03 PM


<%



while(rs.next())

{



if((count%2)==0)

{



color = "#eeffee";





}

else

{

color = "#F9EBB3";

}

count++;







%>

<tr style="background-color:<%=color%>;">

<td><%=count%></td>

<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>


</tr>

<%

}

%>

</table>

<br><br>

<table width="100px" align="center" border=0><tr>

<%

if(count==0)

{

%>

<tr style="background-color:<%=color%>;">

<td colspan=8 align="center">No Record</td>



</tr>

<%

}


System.out.println("Connected to the database");

conn.close();

System.out.println("Disconnected from database");

} catch (Exception e) {

e.printStackTrace();

}
if(offset>1)

{

int previous = offset-1;

%>

<td>

<a href="viewTransAction.jsp?offset=<%=previous%>">Previous</a></td>

<%

}



if(total_page>0)

{

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

{

if(request.getParameter("offset")==null)

{

offset=1;

}

if(i==offset)

{

%>

<td>

<%=i%></td>

<%

}

else{

%>

<td>

<a href="viewTransAction.jsp?offset=<%=i%>"><%=i%></a></td>

<%

}

}}

if(offset<total_page){

int next = offset+1;

%>

<td>

<a href="viewTransAction.jsp?offset=<%=next%>">Next</a></td>

<%

}

%>

</tr>

</table>



</body>

</html>

Thanks

vineet


August 14, 2008 at 3:21 PM


Hi Ragini,



You do some changes in "adduser.jsp";

In function deleteUser() change the code

var delrecord = confirm("Are you sure to delete the record");

if(delrecord)
{
window.location.href=url;

}

In function validate() change the code


var update = confirm("Are you sure to update the record");
if(!update)
{
return false;
}

<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>
<%

Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";

Statement st;

%>

<HTML>
<head>
<script>
function deleteUser(){

var id =document.getElementById("vend_id").value;
var url="process.jsp?vend_id="+id;
var delrecord = confirm("Are you sure to delete the record");

if(delrecord)
{
window.location.href=url;

}
}
function validate(){


if(document.frm.vend_id.value=="")
{

alert("Please enter Id");
document.frm.vend_id.focus();
return false;
}

var update = confirm("Are you sure to update the record");

if(!update)
{
return false;
}


}

</script>

</head>
<BODY>
<FORM NAME="frm" METHOD="post" ACTION="addform.jsp" onsubmit="return validate();">
</BR> </BR>

<H3> <P ALIGN="CENTER"> <FONT SIZE=6> Search User</FONT> </P> </H3> </BR>

<TABLE CELLSPACING=5 CELLPADDING=5 border=0 BGCOLOR="LIGHTBLUE" COLSPAN=2 ROWSPAN=2 ALIGN="CENTER" width="400px">

<TR>
<TD> <FONT SIZE=4>Id</TD>
<TD colspan=2><INPUT TYPE="TEXT" NAME="vend_id" id="vend_id"></td>


</TR>

<TR> <FONT SIZE=6>
<TD colspan=3 align="center">
<INPUT TYPE="Submit" name="submit" VALUE="Update">
<INPUT TYPE="button" name="submit" VALUE="Delete" onclick="deleteUser();">

</TD>
</TR> </FONT>

</FORM>
</BODY>
</HTML>

Thanks

vineet









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads