• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Fetching value from database and add some rows and save in another table

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii all,
I am new to JSP,
M fetching few column values from the table and add one column in which m entering value manually and save all the data in another table while clicking on "Save" Button.

But M not getting the proper output.Please help me out.

I am getting success to get data of Employee Code,Employee name and Dept code from emp_mst.
now I am adding LWP(Leave without Pay) field for all the fetched value.After adding LWP how to save all the data in another table "i.e. leave_mst " while clicking on Submit button..

Following had written my code how it work...Please give me the solution for this..

------------------>

<%

String empmst="select empcd,emp_name,dept_cd from emp_mst";
DBConnection db = new DBConnection();
db.getConnection();
java.sql.ResultSet rs;
rs = db2.getAllData(empmst);

%>
<table border="1">
<tr>
<td>Sr. No.</td>
<td>Employee Code:</td>
<td>Employee Name:</td>
<td>Department Code:</td>
</tr>
<%
while(rs2.next())
{
%>
<tr>
<td>
<%=rs.getRow()%>
</td>
<td>
<input type="text" name="txtempcd" value="<%=rs.getString("empcd")%>"></input>
</td>
<td>
<input type="text" name="txtempname"
value='<%=rs.getString("emp_name")%>'></input>
</td>
<td>
<input type="text" name="txtdeptcd" value="<%=rs.getString("dept_cd")%>"></input>
</td>
<td><input type="text" name="txtsslwp" ></td>
</tr>
<%
}
%>
<tr>
<td>
<input type="Submit" value="Save" name="BtnSubmit">
</td>
</tr>
</table>


<----------------------
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is not the recommended place for doing DB operations. It is better to separate the model and view.
Anyway, if that is not an option for you, you can post the data to a servlet on hitting save and the servlet should take care for committing it to the DB.
 
mehta soham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...
can you tell me in detail about how can i do using servlet...??
can you give bit focus on it....
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mehta Soham wrote:Thanks...
can you tell me in detail about how can i do using servlet...??
can you give bit focus on it....


What sort of help you are looking for? If you want to know more about servlets, you can go through: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic