Helllllllllll

Ads

 
 
 

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

Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads