Helllllllllll

Helllllllllll

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:
Helllllllllll - Java Beginners

Ads