Question: multivalued attribute?

Ads

 
 
 

Share on Google+Share on Google+

maithri
multivalued attribute?
1 Answer(s)      6 years and 2 months ago
Posted in : JSP-Servlet

I have a problem in editing the database through form because of multivalued attribute it is creating the error and also how to write code for displaying the data when there is multivalued attribute? edit.html

edit.jsp
<%
String accno=request.getParameter("acc");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection con=java.sql.DriverManager.getConnection("jdbc:odbc:dms","smartlib","smartlib");
java.sql.Statement stmt1=con.createStatement();
java.sql.ResultSet rs1=stmt1.executeQuery("SELECT a.title,e.author(e.author1,e.author2,e.author3),a.noofcopies,a.category,b.edition,c.pubyear,d.price FROM bookdet a, edition b, publication c, price d,author_det e where (a.accno='"+accno+"') and (a.accno=b.accno and a.accno=c.accno and a.accno=d.accno and a.accno=e.accno)");

%>
<% while(rs1.next()) { %>
<form name="ed" action="http://localhost:8080/examples/jsp/update.jsp" method="post">
<%

while(rs1.next())
{ %>
<table>
<tr> <td> title </td> <td><input type="text" name="title"value=" &lt;%=rs1.getString(1)%>" /> </td> </tr>
<tr> <td> author1 </td> <td><input type="text" name="author1"value=" &lt;%=rs1.getString(2)%>" /> </td> </tr>
<tr> <td> author2 </td> <td><input type="text" name="author2"value=" &lt;%=rs1.getString(3)%>" /> </td> </tr>
<tr> <td> author3 </td> <td><input type="text" name="author3"value=" &lt;%=rs1.getString(4)%>" /> </td> </tr>
<tr> <td> no<em>of</em>copies</td> <td> <input type="text" name="copies" value="&lt;%= rs1.getString(5)%>" /> </td> </tr>
<tr> <td> category </td> <td> <input type="text" name="cat"value="&lt;%=rs1.getString(6)%>" /> </td> </tr>
<tr> <td> edition</td> <td><input type="text" name="edition" value="&lt;%=rs1.getString(7)%>" /> </td> </tr>
<tr> <td> pub<em>year</td> <td><input type="text" name="pub</em>year"value="&lt;%=rs1.getString(8)%>" /> </td> </tr>
<tr> <td> price</td> <td><input type="text" price="price" value="&lt;%=rs1.getString(9)%>" /></td> </tr>


<%} %></p>

<tr><td><input type="submit" value="submit" /> </td> <td> <input type="reset" value="reset" /></td></tr>
</table>
<input type=hidden name="acc" value="<%=accno%>">
</form>

<%

con.close();

} catch(ClassNotFoundException cnfe){
out.println(cnfe.getMessage());

} catch(java.sql.SQLException sqle){
out.println(sqle.getMessage());
}

%>


update.jsp
<% String accno=request.getParameter("acc");
String title=request.getParameter("title");
String copies=request.getParameter("copies");
String cat=request.getParameter("cat");
String edition=request.getParameter("edition");
String pubyear=request.getParameter("pubyear");
String price=request.getParameter("price");
String author1=request.getParameter("author1");
String author2=request.getParameter("author2");
String author3=request.getParameter("author3");
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection con=java.sql.DriverManager.getConnection("jdbc:odbc:dms","smartlib","smartlib");
java.sql.Statement stmt1=con.createStatement();
java.sql.Statement stmt2=con.createStatement();
java.sql.Statement stmt3=con.createStatement();
java.sql.Statement stmt4=con.createStatement();
java.sql.Statement stmt5=con.createStatement();
java.sql.Statement stmt6=con.createStatement();
java.sql.Statement stmt7=con.createStatement();
java.sql.Statement stmt8=con.createStatement();
java.sql.Statement stmt9=con.createStatement();
stmt1.executeUpdate("UPDATE book_det Set title='"+title+"' where accno='"+accno+"'");
stmt2.executeUpdate("UPDATE bookdet Set noof_copies="+copies+" where accno='"+accno+"'");
stmt3.executeUpdate("UPDATE book_det Set category='"+cat+"' where accno='"+accno+"'");
stmt4.executeUpdate("UPDATE edition Set edition='"+edition+"' where accno='"+accno+"'");
stmt5.executeUpdate("UPDATE publication Set pubyear='"+pubyear+"' where accno='"+accno+"'");
stmt6.executeUpdate("UPDATE price Set price="+price+" where accno='"+accno+"'");
stmt7.executeUpdate("UPDATE author_det Set author1="+author1+" where accno='"+accno+"'");
stmt8.executeUpdate("UPDATE author_det Set author2="+author2+" where accno='"+accno+"'");
stmt9.executeUpdate("UPDATE author_det Set author3="+author3+" where accno='"+accno+"'");
con.close(); } catch(ClassNotFoundException cnfe){cnfe.printStackTrace();
} catch(java.sql.SQLException sqle){
sqle.printStackTrace();
}
%>



Ads
View Answers

March 5, 2011 at 12:32 PM


JSP edit multiple values

1)editapplication.jsp:

<%@ page import="java.sql.*" %>
<html>
<form name="form"  method="post" action="retcheck.jsp">
 <table border="1">
<tr><th></th><th>Name</th><th>Address</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 data";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><input type="checkbox" value="<%= rs.getString("id")%>" name="check">
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("address")%></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
<input type="submit" value="Edit">
</form>
</html>

2)retcheck.jsp:

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

<%
String id[]=request.getParameterValues("check");
%>
<form name="form" method=post action="up.jsp">
<table border=1>
<tr><th></th><th>Name</th><th>Address</th></tr>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
for(int a=0;a<id.length;a++){
rs = st.executeQuery("select * from data where id='"+id[a]+"'");
while(rs.next()){ 
    %>
<tr>
<td><input type="hidden" name="id" value="<%=rs.getString("id")%>"></td>
    <td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
    <td><input type="text" name="address" value="<%=rs.getString("address")%>"></td></tr>
      <%
}
}
%>
</table>
<input type="submit" value="update">
</form>

3)up.jsp:

<%@ page import="java.sql.*" %>
<%
String id[]=request.getParameterValues("id");
String name[]=request.getParameterValues("name");
String add[]=request.getParameterValues("address");
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");

Statement st=null;
st=conn.createStatement();
for(int i=0;i<id.length;i++){
st.executeUpdate("update data set  name='"+name[i]+"',address='"+add[i]+"' where id='"+id[i]+"'");
out.println("Data is updated successfully");
}
response.sendRedirect("editapplication.jsp");
%>

Ads









Tutorials   
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values

Ads

 
Advertisement null

Ads