Advertisement
teguhsugiono891208

master

Mar 15th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. //master
  2. <%@ page language="java" import="java.sql.*;"%>
  3. <div class="kotakpemisah"></div>
  4. <div class="kotakhtps">
  5. <center><h3>.: [Data TPS] :.</h3></center>
  6. </div>
  7. <html>
  8. <head>
  9. </head>
  10. <body>
  11. <%
  12. int offset=0;
  13. int ofset = 0;
  14. String tcari = "" ;
  15.  
  16. if(request.getParameter("offset")!=null) {
  17. offset= Integer.parseInt(request.getParameter("offset").toString());
  18. }
  19.  
  20. if(request.getParameter("cari")!=null) {
  21. tcari = String.valueOf(request.getParameter("cari").toString()) ;
  22.  
  23. }
  24. //out.println("tesssss " + tcari);
  25.  
  26. int total_count = 0;
  27. int total_page = 0;
  28. int per_page =15;
  29. String name="";
  30.  
  31. if(offset>1){
  32. ofset = offset*per_page-per_page;
  33. }
  34.  
  35. //System.out.println("MySQL Connect Example.");
  36. Connection conn = null;
  37. String color = "#F9EBB3";
  38. String strQuerycount = "";
  39. String strQuery = "" ;
  40. try {
  41. Class.forName("com.mysql.jdbc.Driver");
  42. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ptmsa_dbo","root" , "");
  43.  
  44. Statement stcount = conn.createStatement();
  45. strQuerycount = "";
  46. strQuerycount = strQuerycount + " select count(*) from tpp_m_tps ";
  47.  
  48. if(tcari.equals("")){
  49. }else{
  50. strQuerycount = strQuerycount + " where Keterangan like '%" + tcari + "%' " ;
  51. }
  52.  
  53.  
  54. ResultSet rscount = stcount.executeQuery(strQuerycount);
  55.  
  56. if(rscount.next()){
  57. total_count=rscount.getInt(1);
  58. }
  59.  
  60. if(total_count%per_page==0){
  61. total_page = total_count/per_page;
  62. }else{
  63. total_page = total_count/per_page+1;
  64. }
  65.  
  66. Statement st = conn.createStatement();
  67. strQuery = "" ;
  68. strQuery = strQuery + "select * from tpp_m_tps ";
  69. if(tcari.equals("")){
  70. }else{
  71. strQuery = strQuery + " where Keterangan like '%" + tcari + "%' " ;
  72. }
  73.  
  74. strQuery = strQuery + " limit "+ofset+","+per_page+" " ;
  75.  
  76. //out.println(strQuery);
  77. ResultSet rs2=null;
  78. ResultSet rs = st.executeQuery(strQuery);
  79.  
  80. int count=0;
  81. if(offset>1)
  82. count=offset*per_page-per_page;
  83. %>
  84.  
  85. <br>
  86. <form action="" method="post">
  87. Cari Data TPS : <input type="text" name="cari" value="${param.cari}"/>
  88. <input type="submit" value=" Cari " class="button"/> <br>
  89. </form>
  90. <br>
  91.  
  92. <table width="600px" align="left" style="border:1px solid #000000;" >
  93. <tr><td colspan=8 align="center" style="background-color:ffeeff"><b>Data TPS</b></td>
  94. </tr>
  95. <tr style="background-color:efefef;">
  96. <td><b> No </b></td>
  97. <td><b> Nama TPS </b></td>
  98. <td><b> KDtps </b></td>
  99. <td><b> Action </b></td>
  100. </tr>
  101.  
  102. <%
  103. while(rs.next()){
  104. if((count%2)==0){
  105. color = "#eeffee";
  106. }else{
  107. color = "#F9EBB3";
  108. }
  109. count++;
  110. %>
  111.  
  112. <tr style="background-color:<%=color%>;">
  113. <td><%=count%></td>
  114. <td><%=rs.getString(2)%> </td>
  115. <td><%=rs.getString(1)%> </td>
  116. <td valign='top'><a href='sedObat?aksi=HAPUS&kd_obat=<%=rs.getString(1)%>'> Hapus</a> |
  117. <a href='beranda.jsp?halaman=tps&aksi=GANTI&kd_tps=<%=rs.getString(1)%>&nm_tps=<%=rs.getString(1)%>'> Edit </a>
  118. </td>
  119. </tr>
  120.  
  121. <%
  122. }
  123. %>
  124.  
  125. </table>
  126. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  127.  
  128. <table width="100px" align="left" border=0>
  129. <tr>
  130. <%
  131. if(count==0){
  132. %>
  133.  
  134. <tr style="background-color:<%=color%>;">
  135. <td colspan=8 align="center">No Record</td>
  136. </tr>
  137. <%
  138. }
  139. //System.out.println("Connected to the database");
  140. conn.close();
  141. //System.out.println("Disconnected from database");
  142. } catch (Exception e) {
  143. e.printStackTrace();
  144. }
  145.  
  146. if(offset>1){
  147. int previous = offset-1;
  148. %>
  149.  
  150. <td><a href="tps.jsp?offset=<%=previous%>">Previous</a></td>
  151. <%
  152. }
  153.  
  154. if(total_page>0){
  155. for(int i=1;i<=total_page;i++)
  156. {
  157.  
  158. if(request.getParameter("offset")==null){
  159. offset=1;
  160. }
  161.  
  162. if(i==offset){
  163. %>
  164. <td><%=i%></td>
  165. <%
  166. }else{
  167. %>
  168. <td><a href="tps.jsp?offset=<%=i%>"><%=i%></a></td>
  169.  
  170. <%
  171. }}}
  172. if(offset<total_page){
  173. int next = offset+1;
  174. %>
  175.  
  176. <td><a href="tps.jsp?offset=<%=next%>">Next</a></td>
  177. <%
  178. }
  179. %>
  180. </tr>
  181. </table>
  182. </body>
  183. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement