• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to enter Date in Oracle from Servlets

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}




}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bit you are missing is something like this:
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
priyanshu bhardwaj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot many my problem is resolved
bye
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic