hi now i am trying to connect oracle database and also insert my data into table, but it's not working.. I created one user registration form. when i give values in the form, i want stored data in oracle table. my table name is logininfoclient_sla. this is my coding:
newuser_db.java
package com.sla; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.PreparedStatement; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class newuser_db */ public class newuser_db extends HttpServlet { private static final long serialVersionUID = 1L; PreparedStatement stmt=null; Connection con =null; ResultSet rs=null; /** * @see HttpServlet#HttpServlet() */ public newuser_db() { super(); // TODO Auto-generated constructor stub } @Override public void init() throws ServletException { // TODO Auto-generated method stub super.init(); try { Class.forName("sun.Jdbc.Odbc.JdbcOdbcDriver"); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } try { con =DriverManager.getConnection("Jdbc:odbc:servletdb","system","balaji"); } catch(SQLException ex) { ex.printStackTrace(); } // TODO Auto-generated method stub } @Override public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException { // TODO Auto-generated method stub super.service(arg0, arg1); PrintWriter out=arg1.getWriter(); String s1=arg0.getParameter("USERID"); String s2=arg0.getParameter("FIRSTNAME"); String s3=arg0.getParameter("LASTNAME"); String s4=arg0.getParameter("EMAILID"); String s5=arg0.getParameter("ORGNAME"); String s6=arg0.getParameter("MOBILENO"); String s7=arg0.getParameter("PHONENO"); String s8=arg0.getParameter("PASSWORD"); out.println("inserted"); out.println(s1); out.println("inserted1"); //String sql="insert into userdetails values(ka.nextval,"+s1+","+s2+","+s3+","+s4+","+s5+","+s6+","+s7+",56,'de',01-jan-98)"; PreparedStatement stmt1; try { stmt1 = con.prepareStatement("insert into login_info_client_sla values(?,?,?,?,?,?,?,?)"); stmt1.setString(1,s1); stmt1.setString(2,s2); stmt1.setString(3,s3); stmt1.setString(4,s4); stmt1.setString(5,s5); stmt1.setString(6,s6); stmt1.setString(7,s7); stmt1.setString(8,s8); //stmt1.executeUpdate(); out.println("inserted2"); stmt1.executeUpdate(); out.println("inserted3"); } catch (SQLException e1) { // TODO Auto-generated catch block out.println(e1); } } @Override public void destroy() { // TODO Auto-generated method stub super.destroy(); try { if(stmt!=null) stmt.close(); stmt=null; } catch (SQLException ex) { ex.printStackTrace(); } try { if(con!=null) con.close(); con=null; } catch (SQLException ex) { ex.printStackTrace(); } } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }
desing jsp page; newuser_reg.jsp
<%@ 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> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form action="newuser_db" method="post"> <center><font size="15" color="agenda">SLA Customer Details</font></center> <table><tr><td>E-Mail id* </td><td>:</td> <td> <input type="text" value="" name="EMAILID"></input></td></tr> <tr><td>First Name* </td><td>:</td> <td> <input type="text" value="" name="FIRSTNAME"></input></td></tr> <tr><td>Last Name* </td><td>:</td> <td> <input type="text" value="" name="LASTNAME"></input></td></tr> <tr><td>Org Name* </td><td>:</td> <td> <input type="text" value="" name="ORGNAME"></input></td></tr> <tr><td>Password* </td><td>:</td> <td> <input type="text" value="" name="PASSWORD"></input></td></tr> <tr><td>Mobile No* </td><td>:</td> <td> <input type="text" value="" name="MOBILENO"></input></td></tr> <tr><td>Phone* </td><td>:</td> <td> <input type="text" value="" name="PHONENO"></input></td></tr> <tr><td></td><td><input type="submit" value="Add"/></td></tr> </table> </form> </body> </html>
please help me.....i am new for this application.....
Ads