aspose file tools*
The moose likes JDBC and the fly likes submit date got from html page in format of DD MON YYYY into oracle database by servlet program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "submit date got from html page in format of DD MON YYYY into oracle database by servlet program" Watch "submit date got from html page in format of DD MON YYYY into oracle database by servlet program" New topic
Author

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

ankur guleria
Greenhorn

Joined: Jan 11, 2014
Posts: 2
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

Joined: Oct 27, 2005
Posts: 19722
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: submit date got from html page in format of DD MON YYYY into oracle database by servlet program