my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Fetching value from database and add some rows and save in another table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Fetching value from database and add some rows and save in another table" Watch "Fetching value from database and add some rows and save in another table" New topic
Author

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

mehta soham
Greenhorn

Joined: May 27, 2009
Posts: 8
Hii all,

I am fetching few column values from the table and add one column on my jsp page in which I am entering value manually and save all the data in another table while clicking on "Save" Button.

But I am 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>



<----------------------

Regards,
Dare Devil
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3738
    
  10

Do not put JDBC code inside of a JSP!


[OCA 8 Book] [Blog]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31419
    
184

Mehta Soham wrote:But I am not getting the proper output.

What are you getting as output and what are you expecting? I'm not following from your description.

Note that it is poor practice to put Java code, especially JDBC, in a JSP. It is much better to use a Java class for this. In particular, it's easier to read, debug, maintain and troubleshoot when not in a JSP.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Fetching value from database and add some rows and save in another table