Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

submit date got from html page in format of DD MON YYYY into oracle database by servlet program

 
ankur guleria
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import java.net.* ;
import java.util.* ;
import java.sql.* ;

public class SecondServlet extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType( "text/html" ) ;
PrintWriter pw = res.getWriter( ) ;

String name=req.getParameter("name");
String email=req.getParameter("email");
String user=req.getParameter("user");
String pwd=req.getParameter("pwd");
String address=req.getParameter("address");
String gender=req.getParameter("gender");
String birthday=req.getParameter("birthday");

HttpSession session = req.getSession(true);
session.setAttribute("name",name);
session.setAttribute("email",email);
session.setAttribute("user",user);
session.setAttribute("password",pwd);
session.setAttribute("address",address);
session.setAttribute("gender",gender);
session.setAttribute("birthday",birthday);
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:sysdba","scott","tiger");
PreparedStatement ps=con.prepareStatement("insert into userdata values(?,?,?,?,?,?,?)");

ps.setString(1,name);
ps.setString(2,email);
ps.setString(3,user);
ps.setString(4,pwd);
ps.setString(5,address);
ps.setString(6,gender);
ps.setString(7,birthday);


int i = ps.executeUpdate();

if(i > 0)
{
pw.println("<BODY BGCOLOR=cyan>");
pw.println("<CENTER><H1>Account Created Successfuly</H1></CENTER>");
pw.println("<CENTER>Home</CENTER>");
pw.println("</table></body>");

}
else
{
pw.println("<BODY BGCOLOR=cyan>");
pw.println("<CENTER><H1>Some Data Is Missing</H1></CENTER>");
pw.println("<CENTER>Home</CENTER>");
}
} // try
catch(Exception e)
{
e.printStackTrace();
pw.println("<BODY BGCOLOR=cyan>");
pw.println("<CENTER><H1>Try Again</H1></CENTER>");
pw.println("<CENTER>Login Again</CENTER>");
}

} // service()
} // class




but after process date value is does not store in database

this is my table----->

CREATE TABLE USERDATA(
NAME VARCHAR2(20),
EMAIL VARCHAR2(30),
USERNAME VARCHAR2(10),
PASSWORD VARCHAR2(20),
ADDR VARCHAR2(20),
GENDER VARCHAR2(5),
BIRTHDAY DATE);

suggest me the convenient solution......
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a SimpleDateFormat to convert the String into a java.util.Date. Then create a java.sql.Date from that, and use ps.setDate to set it instead of ps.setString.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic