aspose file tools*
The moose likes JDBC and the fly likes to enter Date in Oracle from Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "to enter Date in Oracle from Servlets" Watch "to enter Date in Oracle from Servlets" New topic
Author

to enter Date in Oracle from Servlets

priyanshu bhardwaj
Greenhorn

Joined: Jul 30, 2005
Posts: 20
if i want to code so that the date should be entered in the database when entered in a textbox at the client side like 12/3/05 then how should I do it
if I tke request.getParameter("from date");
then in pst.setDate(fieldnumber,from date);
how should i code this
I m also giving the code
Please help


import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class schemeservlet extends HttpServlet
{
String fromdate1String schcost1;

Connection con=null;
PreparedStatement pst=null;
Statement stmt=null;
ResultSet rs=null;


public void init(ServletConfig config) throws ServletException
{
super.init(config);

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc ata");

}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}

public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
doPost(req,res);
}

public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
int j;
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
HttpSession s=req.getSession(true);
String str = req.getQueryString();

try
{

int add=str.lastIndexOf("ad.x");





if(add>0)
{

schfromdate1=req.getParameter("schfromdate");
schtodate1=req.getParameter("schtodate");
doinsert(schno1,prodno1,schname1,schfromdate1,schtodate1,schdetail1,schcost1,schbenefit1,invvalue1,schregion1,schcategory1,schapplied1,schbenqty1,schper1,schtype1,pw);
res.sendRedirect("http://localhost:8080/examples/schemeR.jsp");
{
public void doinsert(String fromdate,{
System.out.println("insert");
String sqlint="insert into Scheme" +
sch_from_date)"
+ "values(?)";

try {
pst=con.prepareStatement(sqlint);
}
catch(SQLException e)
{
System.out.println(e);
}


int i=0;

try
{
System.out.println("inside insert executed");
pst=con.prepareStatement(sqlint);
pst.setString(4,schfromdate);
System.out.println("after insert executed");
i=pst.executeUpdate(sqlint);

catch(Exception e)
{
System.out.println(e);
}




}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Moved to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

The bit you are missing is something like this:
Babar Qadri
Ranch Hand

Joined: Oct 12, 2004
Posts: 51
try this
, i made some additions in your code


try
{

//added line
SimpleDateFormat sdf = new SimpleDateFormat("MM.dd.yyyy");

int add=str.lastIndexOf("ad.x");





if(add>0)
{

schfromdate1=req.getParameter("schfromdate");
schtodate1=req.getParameter("schtodate");
doinsert(schno1,prodno1,schname1,schfromdate1,schtodate1,schdetail1,schcost1,
schbenefit1,invvalue1,schregion1,schcategory1,schapplied1,
schbenqty1,schper1,schtype1,pw);
res.sendRedirect("http://localhost:8080/examples/schemeR.jsp");
{
public void doinsert(String fromdate, {
System.out.println("insert");
String sqlint="insert into Scheme" +
"(sch_from_date)"
+ "values(?)";

try {
pst=con.prepareStatement(sqlint);
}
catch(SQLException e)
{
System.out.println(e);
}


int i=0;

try
{
System.out.println("inside insert executed");
pst=con.prepareStatement(sqlint);

////added line
pst.setDate(1,new java.sql.Date( sdf.parse(schfromdate()).getTime()));


System.out.println("after insert executed");
i=pst.executeUpdate(sqlint);

catch(Exception e)
{
System.out.println(e);
}




}
[ December 08, 2005: Message edited by: Babar Qadri ]

babar
priyanshu bhardwaj
Greenhorn

Joined: Jul 30, 2005
Posts: 20
Thanks alot many my problem is resolved
bye
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to enter Date in Oracle from Servlets
 
Similar Threads
Servlet
simple coding, still not working, may day!!!!
How to store and retrieve images to MS access and MYsql database
about hidden from fields
HTML-Servlet-MYSQL problem ? help needed?