Jamsiya N P
question
2 Answer(s)      a year and 11 months ago
Posted in : Java Beginners

Hi good morning Sir,

  1. Use grid -That displays employee name,employee_id,status(P/A),check box or Approve button. (Button in each row of the grid and below a button for approving all attendances marked )-using java/jsp + mysql.
View Answers

June 1, 2011 at 5:15 PM


1)approveApplication.jsp:

<%@ page import="java.sql.*" %>
<html>
<script>
function check(v){
    var f=document.form;
    f.method="post";
    f.action='approve.jsp?id='+v;
    f.submit();
}
function check_all_in_document(doc)
{
  var c = new Array();
  c = doc.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].type == 'checkbox')
    {
      c[i].checked = true;
    }
  }
}

function checkAll()
{
  check_all_in_document(window.document);
  for (var j = 0; j < window.frames.length; j++)
  {
    check_all_in_document(window.frames[j].document);
  }
}
</script>
<form name="form"  method="post" action="approveall.jsp" onsubmit="return checkem();">
 <table border="1">
<tr><th>ID</th><th>Name</th><th>Status</th><th></th></tr>
<%
int i=0;
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr>
<td><input type="text" name="id" value="<%=rs.getString("id")%>"></td>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="status" value="<%=rs.getString("status")%>"></td>
<td><input type="checkbox" value="<%=rs.getString("id")%>"  onclick='check(<%=rs.getString("id")%>);' name="checkboxes"></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
<input type="submit" value="Approve All">
</form>
</html>

June 1, 2011 at 5:16 PM


2)approve.jsp:

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

<%
String value=request.getParameter("id");
int id=Integer.parseInt(value);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=conn.createStatement();
int i=st.executeUpdate("update employee set status='Approve' where id="+id+"");
response.sendRedirect("/examples/jsp/Example2/approveApplication.jsp");
%>

3)approveall.jsp:

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

<%
String values[]=request.getParameterValues("checkboxes");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=conn.createStatement();
for(int i=0;i<values.length; i++){
int id=Integer.parseInt(values[i]);
st.executeUpdate("update employee set status='Approve' where id="+id+"");
}
response.sendRedirect("/examples/jsp/Example2/approveApplication.jsp");
%>









Related Pages:
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.