Home Discussion Discuss: insert into statement in sql using servlets

  • table contain null valuesjiji March 29, 2011 at 5:32 PM

    The Source code is successfully running. But there is no jsp pages. and the table contain null values. please help me

  • few words about site Rajashekhar Reddy Bhuma April 7, 2011 at 11:35 PM

    I felt very happy after reading this example. thank you roseindia

  • servlet codeAnand October 8, 2011 at 4:29 PM

    I have to browse multiple files and store into database and HTML with java servlet code for email sending please send code as soon as possible

  • thank you very muchsujeeth reddy December 10, 2011 at 8:36 AM

    hello, I had a problem with jsp inserting values in to mysql,but my problem solved with this. I used net beans, in that make sure that you put url pattern with .java extension.

  • hellosheetal January 7, 2012 at 1:08 AM

    this code helped a lot.thanks

  • commentrajesh February 8, 2012 at 1:14 AM

    good

  • insert into DB using jsp & servletvijay February 8, 2012 at 1:28 AM

    i.create a jsp page <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript"> function getMonth(val) { var monthArray = new Array("JAN","FEB","MAR","APR","MAY","JUN", "JUL","AUG","SEP","OCT","NOV","DEC"); for (var i=0; i<monthArray.length; i++) { if (monthArray[i].toLowerCase() == val.toLowerCase()) { return(i); } } return(-1); } function checkDate(fld) { var success = true; var mo, day, yy, testDate; var val = fld.value; var re = new RegExp("[0-9]{1,2}[-][A-z]{3}[-][0-9]{4}", "g"); if (re.test(val)) { var delimChar = "-"; var delim1 = val.indexOf(delimChar); var delim2 = val.lastIndexOf(delimChar); day = parseInt(val.substring(0,delim1),10); mo = getMonth(val.substring(delim1+1,delim2),10); yy = parseInt(val.substring(delim2+1),10); testDate = new Date(yy,mo,day); if (testDate.getDate() == day) { if (testDate.getMonth() == mo) { if (!testDate.getFullYear() == yy) { alert("Invalid year Entry"); fld.focus(); fld.value=""; success = false; } if((yy<=1987)||(yy>=2020)){ alert("Invalid Year Entry"); fld.focus(); fld.value=""; success = false; } else { } } else { alert("Invalid month entry"); fld.focus(); fld.value=""; success = false; } } else { alert("Invalid day entry."); fld.focus(); fld.value=""; success = false; } } else { alert("Incorrect date format.Enter dd-mon-yyyy"); fld.focus(); fld.value=""; success = false; } return(success); } function checkForm() { var getBank=document.Accountform.bankName.value; var alphaExp = /^[\,\ \-0-9a-zA-Z]+$/; var message=""; r=document.Accountform.MitStudentId.value ; if(document.Accountform.MitStudentId.value==""){ document.getElementById("error_MitStudentId").innerText = "*Enter Mit Student Id"; message=message+"Enter the Mit Student Id"; } else if(r.charAt(0)=="0"){ document.getElementById("error_MitStudentId").innerText = "*Enter non zero Mit Student Id"; message=message+"Enter the Mit Student Id"; } else if(document.Accountform.MitStudentId.value.length!=6){ document.getElementById("error_MitStudentId").innerText = "*Enter 6 digits Mit Student Id"; message=message+"Enter the Mit Student Id"; } else{ document.getElementById("error_MitStudentId").innerText = ""; } x=document.Accountform.studentAccountNo.value; if(document.Accountform.studentAccountNo.value==""){ document.getElementById("error_studentAccountNo").innerText = "*Enter StudentID"; message=message+"Enter the Student Id"; } else if(x.charAt(0)=="0"){ document.getElementById("error_studentAccountNo").innerText = "*Enter non zero Student Id"; message=message+"Enter the Student Id"; } else if(document.Accountform.MitStudentId.value.length!=6){ document.getElementById("error_MitstudentAccountNo").innerText = "*Enter 6 digits Student Id"; message=message+"Enter the Student Id"; } else{ document.getElementById("error_MitstudentAccountNo").innerText = ""; } y=document.Accountform.MitAccountNo.value; if(document.Accountform.MitAccountNo.value==""){ document.getElementById("error_MitAccountNo").innerText = "*Enter AccountID"; message=message+"Enter the Account Id"; } else if(y.charAt(0)=="0"){ document.getElementById("error_MitstudentAccountNo").innerText = "*Enter non zero AccountID"; message=message+"Enter the AccountID"; } else if(document.Accountform.MitStudentId.value.length!=6){ document.getElementById("error_studentAccountNo").innerText = "*Enter 6 digits AccountID"; message=message+"Enter the AccountID"; } else{ document.getElementById("error_MitAccountNo").innerText = ""; } if(getBank=="none"){ document.getElementById("error_committedamount").innerText = "*Select Committed Amount "; message=message+"Select Committed Amount"; } else{ document.getElementById("error_committedamount").innerText = ""; } if(document.Accountform.dateOfOpening.value==""){ document.getElementById("error_dateOfOpening").innerText = "*Enter the Date"; message=message+"Enter the Date"; } else{ document.getElementById("error_dateOfOpening").innerText = ""; } if(getBank=="none"){ document.getElementById("error_bank").innerText = "*Select Bank"; message=message+"Select Bank"; } else{ document.getElementById("error_bank").innerText = ""; } if(document.Accountform.accountType.value=="none"){ document.getElementById("error_accountType").innerText = "*Select Type"; message=message+"Select Year"; } else{ document.getElementById("error_accountType").innerText = ""; } if(message=="") return true; else return false; } function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode; if ( ( charCode > 47 && charCode < 58 ) || charCode ==127 || charCode ==8) return true; alert("Enter only the numbers"); return false; }window.history.forward(); /* function noBack() { window.history.forward(); } */ function checknull() { c=document.getElementById("commAmount").value; var numericExpression = /^[0-9]+$/; if ((c!=1000&& c!=2000 && c!=3000 && c!=4000 && c!=5000) || (c.match(numericExpression)==null)) { alert("Enter only multiples of 1000 and upto 5000"); flag=1; } } </script> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>NM</title> <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <%-- <%if(session.getAttribute("name")==null||session.isNew()) response.sendRedirect("Home.jsp");%> <%session.setMaxInactiveInterval(20000);%> --%> <div id="header"> <a href="${pageContext.request.contextPath}/jsp/Home.jsp" rel="stylesheet"><img id="logo" src="${pageContext.request.contextPath}/images/logo-Mit1.JPG" alt=""width="200" height="200"/></a> <div id="menu"> <ul> <li><a href="${pageContext.request.contextPath}/jsp/MitWelcome.jsp">Home</a></li> <li><a href="${pageContext.request.contextPath}/jsp/Home.jsp">Log Out</a></li> </ul> </div> <h1><font size="5" color="white"><br/> N</font></h1> </div><!-- header --> <div id="main"><div id="main2"> <h3>Create Mit Account</h3> <body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload=""oncontextmenu="return false;"> </div> <form method="post" name="Accountform" onSubmit="return checkForm()" action="<%=request.getContextPath()%>/AccountController"> <input type="hidden" name="page" value="Mitaccount"/> <table border="0" STYLE="margin-left:150px;margin-top:20px;"> <tr> <td>MitStudentId <span class=mandatory>*</span></td> <td><input type="text" id="MitStudentId" name="MitStudentId" maxlength="6" style="width:153px;" onKeyPress="return isNumberKey(event)"/></td> <td><div id="error_MitStudentId"></div></td> </tr> <tr> <td>MitstudentAccountNo <span class=mandatory>*</span></td> <td><input type="text" id="MitstudentAccountNo" name="MitstudentAccountNo" maxlength="6" style="width:153px;" onKeyPress="return isNumberKey(event)"/></td> <td><div id="error_MitstudentAccountNo"></div></td> </tr> <tr> <td>MitAccountNo<span class=mandatory>*</span></td> <td><input type="text" id="MitAccountNo" name="MitAccountNo" maxlength="6" style="width:153px;" onKeyPress="return isNumberKey(event)"/></td> <td><div id="error_MitAccountNo"></div></td> </tr> <tr> <td>Bank name<span class=mandatory>*</span></td> <td> <select name="bankName" id="course" style="width:158px;"> <option value="none">----Select Bank----</option> <option >Indian Bank</option> <option >State Bank of India</option> <option >Punjab National Bank</option> <option >Syndicate Bank</option> <option >Oriental Bank of Commerce</option> </select> </td> <td><div id="error_bank"></div></td> </tr> <tr> <td>Committed Amount<span class=mandatory>*</span></td> <td> <select name="commAmount" id="course" style="width:158px;"> <option value="none">----Select Committed Amount----</option> <option >1000</option> <option >2000</option> <option >3000</option> <option >4000</option> <option >5000</option> </select> </td> <td><div id="error_committedamount"></div></td> </tr> <%-- <tr> <td>Committed Amount<span class=mandatory>*</span></td> <td><input type="text" id="commAmount" maxlength="4" name="commAmount" onchange="return checknull()"/></td> <td><div id="error_committedamount"></div></td> </tr> --%> <tr> <td>dateOfOpening<span class=mandatory>*</span></td> <td><input type="text" id="dateOfOpening" name="dateOfOpening" onChange="return checkDate(this)"/></td> <td><div id="error_dateOfOpening"></div></td> </tr> <tr> <td>AccountType<span class=mandatory>*</span></td> <td> <select name="accountType" id="course" style="width:158px;"> <option value="none">----Select Type----</option> <option >Saving Type</option> <option >Related Type</option> </select> </td> <td><div id="error_accountType"></div></td> </tr> <tr></tr><tr></tr><tr></tr><tr> <td><center><input type="submit" name="sub" value="CREATE"></center></td> <td><center><input type="Reset" name ="rename" value="RESET"></center></td> <td></td> </tr> </table> <br></br> </form></div> </body> </html> 2. servlet in dopost if (request.getParameter("page").equalsIgnoreCase("Mitaccount")) { AccountDao dao=new AccountDao(); try { String MitStudentId = request .getParameter("MitStudentId"); String studentAccountNo = request .getParameter("studentAccountNo"); String MitAccountNo = request .getParameter("MitstudentAccountNo"); String bankName = request.getParameter("bankName"); String committedAmount = request.getParameter("commAmount"); String dateOfOpening = request .getParameter("dateOfOpening"); String AccountType = request.getParameter("Accounttype"); AccountBean bean = new AccountBean(); bean.setMitStudentId(MitStudentId); bean.setStudentAccountNo(Integer.parseInt(studentAccountNo)); bean.setMitAccountNo(Integer.parseInt(MitAccountNo)); bean.setBankName(bankName); bean.setCommAmount(Integer.parseInt(committedAmount)); bean.setDateOfOpening(dateOfOpening); bean.setAccountType(AccountType); dao.checkhistory(bean); int history =bean.getHistory(); if(history==0) { AccountDao insertDao= new AccountDao(); try { insertDao.dbInsert(bean); request.getRequestDispatcher("/jsp/MitCreatedOut.jsp").forward(request, response); } catch (SQLException e) { e.printStackTrace(); } } else{ request.getRequestDispatcher("/jsp/MitCreateError.jsp").forward(request, response); } } catch (Throwable theException) { System.out.println(theException); } } 3.Data Access Object: public void dbInsert(AccountBean bean)throws Exception,SQLException{ Connection con=DbUtil.getConnection(); int balance=0; int history=1; @SuppressWarnings("unused") ResultSet rs=null; String sql="insert into BANKACCOUNT values(?,?,?,?,?,?,?,?,?)"; PreparedStatement state=con.prepareStatement(sql); state.setString(1,bean.getNsepStudentId()); state.setInt(2,bean.getStudentAccountNo()); state.setInt(3,bean.getNsepAccountNo()); state.setString(4,bean.getBankName()); state.setInt(5,bean.getCommAmount()); state.setString(6,bean.getDateOfOpening()); state.setString(7,bean.getAccountType()); state.setInt(8,balance); state.setInt(9,history); rs=state.executeQuery(); } public void checkhistory(AccountBean b) { Connection con=null; ResultSet rs=null; try { con=DbUtil.getConnection(); PreparedStatement state=con.prepareStatement("select history from NSEPBANKACCOUNT where nsepStudentId =?"); state.setString(1,b.getMitStudentId()); rs=state.executeQuery(); while(rs.next()) { int history=rs.getInt("history"); b.setHistory(history); } } catch(Exception e) { } finally{ try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } DB Connection: package com.nsep.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; import com.nsep.constants.*; @SuppressWarnings("unused") public class DbUtil { static Connection con; static String url; public static Connection getConnection() throws ClassNotFoundException, SQLException { String url = ConstantAccount.URL; String userName=ConstantAccount.USERNAME; String passWord=ConstantAccount.PASSWORD; Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection(url,userName,passWord); return con; } } for constant class package com.nsep.constants; import java.sql.Connection; public class ConstantAccount { static Connection con; public static String URL = "jdbc:oracle:thin:@xxx:portno:servicename"; public static String USERNAME="xxx"; public static String PASSWORD="yyy"; }

  • inserting data into ms accesschaitra March 5, 2012 at 4:48 PM

    i need complete procedure for executing this code in netbeans using ms-access as my back-end and java as front end,using servlets,DAO,beans....plz let me know as soon as possible,it is urgent....i am unable to run this code properly

  • errorrosy June 20, 2013 at 5:27 PM

    I had downloaded a program from your link http://www.roseindia.net/servlets/ServletUserEnquiryForm.shtml i am getting an error given below SQLException caught: No suitable driver found for jdbc:SQL Server://http://localhost:8080/DEMO/ServletUserEnquiryForm Please suggest ThankYou

  • error rosy June 21, 2013 at 1:47 PM

    Hi i am using program dispaly at http://www.roseindia.net/servlets/ServletUserEnquiryForm.shtml but now my queries are 1) info are not store in my db sql server. 2)my output is Hello: null plz suggest me at rosy.bakshi1@yahoo.com

  • J2EEtejomay July 12, 2013 at 1:02 PM

    ITZ AWSME TO LEARN FROM HERE

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
JDBC Questions

SQL STATEMENT in JDBC in NETBEANS IDE
SQL STATEMENT in JDBC in NETBEANS IDE  Iam using NETBEANS IDE. Iam developing a bank application. Using JDBC in SERVLETS For the withdraw function, "bal" and "ano" are user inputs when i wrote like, st.executeQuery("UPDATE 

Quartz Tutorials

SQL And Statement
SQL AND Statement       The SQL AND operator is used to show you the filter records... with Example The Tutorial illustrates an example from SQL AND Statement 

Servlets

insert into statement in sql using servlets
insert into statement in sql using servlets   ... insert a value from a html form in the table stored in the database. ... we are going to insert the values. Now make one jsp page or  html page 

SQL Question

fetching data using servlets - SQL
for fetching data from a ORACLE10g database using SERVLETS.   Hi Friend...fetching data using servlets  I have successfully made connection with the oracle10g database that i am using and also able to put in data using JSP 

SQL Question

to write an SQL query using insert statement
to write an SQL query using insert statement  I need to write an sql query for the below using InSERT command.pls help. Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL 

JDBC Questions

UNICODE or SQL statement issue - JDBC
UNICODE or SQL statement issue  Hi again............ I have got something new that........... i was using MS Access as the database with my... ..... The output to display is fetched from the database which is connected using DSNless 

Quartz Tutorials

SQL Backup query with where statement
SQL Backup query with where statement       SQL Backup query with where statement ...()); Insert Data Into Stu_Table Insert into statement add the records 

JSP Servlet Questions

Upload CSV File into Columns of sql table using servlets and jsp
Upload CSV File into Columns of sql table using servlets and jsp  Hello sir, plz give me the code to upload csv file data into respective columns of table 

JSP Servlet Questions

servlets - JSP-Servlet
("SQL statement is not executed!"); } } catch (Exception e...servlets  i need a help to write a program on employee details using servlets.  Hi friend, employee form in servlets 

Servlet Interview Questions

servlets
servlets  why we are using servlets 

Servlet Interview Questions

servlets
servlets  How do you communicate between the servlets?   We can communicate between servlets by using RequestDespatcher interface and servlet chaining 

JSP Servlet Questions

servlets
servlets  How to open and read the contents of a text file in servlets?   Please visit the following link: Read text file using Servlet 

Servlet Interview Questions

servlets
are the differ ways you can communicat between servlets   Different ways of communicating between servlets:- 1)Using RequestDispatcher object. 2)Sharing resource using ServletContext object. 3)Include response of the resource 

Servlet Interview Questions

servlets
regarding the user usage and habits. Servlets sends cookies to the browser client using the HTTP response headers. When client gets the cookie information it?s... the cookie information using the HTTP request headers. When cookie based session 

JSP Servlet Questions

servlets
servlets  hi i am using servlets i have a problem in doing an application. in my application i have html form, in which i have to insert on date... into java.sql.Date type and insert into database 

Servlet Interview Questions

servlets
in servlets   There are four ways of authentication:- HTTP basic... send by theclient. The password is sent using simple base64 encoding but it?s... and transmitted using SHA or MD5. HTTPS client authentication HTTPS client 

Servlet Interview Questions

servlets
functionality to the servlets apart from processing request and response paradigm... of filters. A filter is configured in a web.xml file. The class using 

SQL Question

SQL statement - SQL
SQL statement  Hi, i have an sql statement that needs to add the price, vat and shipping cost. It works fine but one problem is that the shipping... be charged 10. otherwise nothing. Heres the code: $orderAmount = 0; $sql 

Servlet Interview Questions

servlets
how do we share data using getservletcontext servlets  how do we share data using getservletcontext 

SQL Tutorial

SQL Backup query with where statement
SQL Backup query with where statement       SQL Backup query with where statement ...),Stu_Class()); Insert Data Into Stu_Table Insert into statement add 

Development process Questions

Servlets
", " "); pstm=con.prepareStatement("insert into stureg...); int i = pstm.executeUpdate(); String sql = "select...(sql); ResultSet rs = prest.executeQuery 

Development process Questions

Servlets
, "PRATAP", " "); pstm=con.prepareStatement("insert into stureg...); int i = pstm.executeUpdate(); String sql = "select...(sql); ResultSet rs = prest.executeQuery 

Servlet Interview Questions

servlets
implementing filter using apache tomcat in servlets  can you explain in short how do you go about implementing filter using apache tomcat   Please visit the following links: Logging Filter Servlet Example    

SQL Tutorial

SQL AND Statement
SQL AND Statement       The SQL AND operator is used to show you the filter records... with Example The Tutorial illustrates an example from SQL AND Statement 

JSP Servlet Questions

Servlets
= DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st=con.createStatement(); int i=st.executeUpdate("insert 

Servlet Interview Questions

servlets
are not supported by all web servers. So before using SSI read the web server 

JSP Servlet Questions

servlets
the methods they need. But actually using the HttpServlet class itself make no sense 

Servlet Interview Questions

the servlets
;/context-param> We can access the Init parameter in the servlet using 

Java Beginners

servlets
servlets  how can I run java servlet thread safety program using tomcat server? please give me a step by step procedure to run the following program my program is A DEMO PROGRAM FOR THREAD SAFETY. package serv; import 

SQL Question

The Update Statement in SQL.
The Update Statement in SQL.  The Update Statement in SQL.   Hi, here is the answer, The update statement in the sql is written as follows- UPDATE table_name SET column_name = new_value WHERE column_name = some_value 

DMCA.com