multivalued attribute?

multivalued attribute?

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();
}
%>



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");
%>









Related Tutorials/Questions & Answers:
multivalued attribute
multivalued attribute?
Advertisements
multivalued attribute?
ModuleNotFoundError: No module named 'multivalued-dict'
Cookies Attributes
Version of commons-attributes>commons-attributes-api dependency
Version of commons-attributes>commons-attributes-compiler dependency
Version of commons-attributes>commons-attributes-plugin dependency
ModuleNotFoundError: No module named 'attributes'
ModuleNotFoundError: No module named 'attributes'
Manipulating attributes
DTD-Attributes
XSD Attributes
Artifacts of commons-attributes
Setting File Attributes
Setting File Attributes
Setting File Attributes
ModuleNotFoundError: No module named 'attributes-doc'
ModuleNotFoundError: No module named 'django-attributes'
ModuleNotFoundError: No module named 'django-attributes'
ModuleNotFoundError: No module named 'django-attributes'
ModuleNotFoundError: No module named 'hybrid-attributes'
ModuleNotFoundError: No module named 'pandoc-attributes'
ModuleNotFoundError: No module named 'pynamodb-attributes'
ModuleNotFoundError: No module named 'attributes-doc'
ModuleNotFoundError: No module named 'bw-attributes'
ModuleNotFoundError: No module named 'django-attributes'
ModuleNotFoundError: No module named 'hybrid-attributes'
Setting File Attributes
XML Attributes
Maven Repository/Dependency: commons-attributes | commons-attributes-plugin
Maven Repository/Dependency: commons-attributes | commons-attributes-compiler
Maven Repository/Dependency: commons-attributes | commons-attributes-api
EJB Transactional Attributes
ModuleNotFoundError: No module named 'ldap-attributes-selector'
ModuleNotFoundError: No module named 'odoo8-addon-medical-medicament-attributes'
ModuleNotFoundError: No module named 'read-only-attributes'
ModuleNotFoundError: No module named 'read-only-class-attributes'
ModuleNotFoundError: No module named 'djangocms-attributes-field'
ModuleNotFoundError: No module named 'django-field-attributes'
ModuleNotFoundError: No module named 'django-mp-attributes'
ModuleNotFoundError: No module named 'flake8-class-attributes-order'
Maven Dependency commons-attributes-api >> 2.1
Maven Dependency commons-attributes-api >> 2.2
Maven Dependency commons-attributes-compiler >> 2.1
Maven Dependency commons-attributes-compiler >> 2.2
Maven Dependency commons-attributes-plugin >> 2.1
Deleting Two Attributes
Context attributes in Servlet
Getting Attributes And its Value

Ads