Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Paging in Java

Fri Aug 01, 2008 8:07 am

I am trying to develope a Application using Java Swing,JDBC & My Sql. Now I am unable to do recordset paging. i.e I want to show 10 records at a time . Then I will press next for next 10 Records. I also want to give some page number in a Jbutton Dynamicaly to go directly to that set of 10 records. Please give me solution.

Happy Coding
Karumanchi



Re: Paging in Java

Fri Aug 01, 2008 12:27 pm

hi my friend,
i made the paging before in a web application i wrote before ,here is the function that do this :
java code
public String DoFilmSearch(String page) throws IOException
{

String returnTable = "";

if(page==null)page="1";
int mypage=Integer.parseInt(page);
int myBase=(limit*mypage)-limit;
int myLimit=(limit);
boolean flag=false;
try{
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/subarabia?user=root&password=11991199");

Statement statement = connection.createStatement();

String sql="Select Films.FILM_ID,FILM_NAME As 'Film name' ,COUNT(TRGMA_ID)As 'Subtitles' ,FILM_YEAR" +
" from Films Left join Trgma on(Films.FILM_ID=Trgma.FILM_ID) where FILM_NAME like('%"+Filmname+"%')" +
" group by FILM_NAME,FILM_YEAR order by 'Film name' ,Subtitles limit "+myBase+","+myLimit+ ";";
ResultSet myresult= (ResultSet) statement.executeQuery(sql);

ResultSetMetaData myMetaData =(ResultSetMetaData) myresult.getMetaData();
int size=myMetaData.getColumnCount();


returnTable= "<table >";
returnTable+="<tr >";
for(int i=2;i<=size-1;i++)
{
returnTable+="<th>"+myMetaData.getColumnName(i)+"</th>";
}
returnTable+="</tr>";

while(myresult.next())
{
returnTable+="<tr>";

flag=true;
returnTable+="<td><a href=FilmTrgma.jsp?FILM_ID="+myresult.getString(1)+">"+myresult.getString(2)+"</a> ("+myresult.getString(4)+")"+"</td>";
returnTable+="<td>"+myresult.getString(3)+"</td>";


returnTable+="</tr>";
}
if(!flag)
returnTable+="<tr><td colspan=2> No results found </td></tr>";

sql="Select COUNT(FILM_ID) from Films where FILM_NAME like('%"+Filmname+"%')";
myresult= (ResultSet) statement.executeQuery(sql);
myresult.next();
returnTable+="<tr><td colspan=2>Page: ";
int count=myresult.getInt(1);
int i=0;
while(count>0)
{
i++;
if(i!=Integer.parseInt(page))
returnTable+="<a href=FilmSearchResult.jsp?page="+i+"&&Filmname="+Filmname+">"+i+"</a>|";
else
returnTable+="<u>"+i+"</u>|";
count-=limit;
}
returnTable+="</table> ";
connection.close();
statement.close();

}

catch (SQLException ex) {
ex.printStackTrace();
}

return returnTable;


}


Post a reply
  Related Posts  to : Paging in Java
 Paging problem in php     -  
 XML Paging Code     -  
 paging JPA Query result     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 What is Java API?!!!     -  
 java or .net     -  
 need help in java     -  
 Using FTP in java     -  
 what is java     -  
 Java course     -