save html table in bd using jsf or jsp

2

I have a dynamic HTML table

<TABLE>
<TR>
    <TD align="center">ID Interno</TD>
    <TD align="center">UID Externo</TD>
    <TD align="center">ID Interno</TD>
    <TD align="center">UID Externo</TD>
</TR>
<TR>
    <TD><input type="text"/></TD>
    <TD><input type="text"/></TD>
    <TD><input type="text"/></TD>
    <TD><input type="text"/></TD>
</TR>
</TABLE>

I want to go through it and save the contents of its manually filled lines in a database. I'm doing a web application on JAVA and I want to ask if anyone can help me on how to do it using JSF or JSP.

    
asked by Yassine 22.08.2016 в 08:23
source

1 answer

1

If you modify the following example, you will have what you need.

 <html>
 <head><title>Enter to database</title></head>
 <body>
 <table>
 <%@ page import="java.util.*" %>
 <%@ page import="javax.sql.*;" %>
 <% 

 java.sql.Connection con;
 java.sql.Statement s;
 java.sql.ResultSet rs;
 java.sql.PreparedStatement pst;

 con=null;
 s=null;
 pst=null;
 rs=null;

 // Remember to change the next line with your own environment
 String url= 
 "jdbc:jtds:sqlserver://nameofyourdatabaseserver.or.ipaddress/yourdatabasename";
 String id= "username";
 String pass = "password";
 try{

      Class.forName("net.sourceforge.jtds.jdbc.Driver");
      con = java.sql.DriverManager.getConnection(url, id, pass);

 }catch(ClassNotFoundException cnfex){
      cnfex.printStackTrace();

 }
 String sql = "select top 10 * from tbl_sys_user";
 try{
      s = con.createStatement();
      rs = s.executeQuery(sql);
 %>

 <%
 while( rs.next() ){
 %><tr>
 <td><%= rs.getString("cust_id") %></td>
 <td><%= rs.getString("rdate") %></td>
 <td><%= rs.getString("email") %></td>
 </tr>
 <%
 }
 %>

 <%

 }
 catch(Exception e){e.printStackTrace();}
 finally{
      if(rs!=null) rs.close();
      if(s!=null) s.close();
      if(con!=null) con.close();
 }

 %>

 </body>
 </html>
    
answered by 22.08.2016 в 10:48