Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa JSP-Servlet multivalued attribute

Have Programming Question? Ask it here!

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

I have a author as multivalued attribute and i have inserted values for it in database but now how to insert values in the database through form .I have written query as shown below and iam getting error .

String query4="INSERT INTO author_det(accno,isbn,author) VALUES ('"+accno+"','"+isbn+"','"+author+"')"; stmt.executeUpdate(query4);

View Answers

March 4, 2011 at 12:37 PM

Jsp insert data into database


<form method="post" action="insertdata.jsp">
<tr><td>Enter Acc No:</td><td><input type="text" name="accno"></td></tr>
<tr><td>Enter ISBN:</td><td><input type="text" name="isbn"></td></tr>
<tr><td>Enter Author:</td><td><input type="text" name="author"></td></tr>
<tr><td></td><td><input type="submit" value="submit"></td></tr>


<%@page import="java.sql.*,java.util.*"%>
int ano=Integer.parseInt(request.getParameter("accno"));
int isbn=Integer.parseInt(request.getParameter("isbn"));
String name=request.getParameter("author");
ArrayList list=new ArrayList();
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        Statement st=con.createStatement();
        int i=st.executeUpdate("insert into author_det(accno, isbn,author) values("+ano+","+isbn+",'"+name+"')");
        out.println("Data is successfully inserted into database.");
        catch(Exception e){

3)table author_det:

CREATE TABLE `author_det` (                              
              `id` bigint(255) NOT NULL auto_increment,              
              `accno` int(255) default NULL,                         
              `isbn` int(255) default NULL,                          
              `author` varchar(255) default NULL,                    
              PRIMARY KEY  (`id`)                                    

Related Tutorials/Questions & Answers: