File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic


aparna rudra

Joined: Apr 06, 2004
Posts: 14
i am trying to insert data in database this program compiles but doesnt work. have been struggling past 3 days, plzz anyone help me to solve this problem.

i am using jbuilder for this. please anyone help me in solving this. i get the error as data not found,null pointer exception....... wht do i do?
please help me.


package spackage;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Date;
import java.sql.*;
import java.text.*;

* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0

public class Servletin extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
Statement st;
//Initialize global variables

public void init(ServletConfig sc) throws ServletException {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:appy");
st = con.createStatement();
catch(Exception e){
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

/* String df = request.getParameter("dateofflight");
String df2 = " ";
try {
SimpleDateFormat sdf = new SimpleDateFormat(df);
// String df3= sdf.parse(df);
System.out.println("Date u entered is correct =" + df2 + "(" + df + ")");
catch (Exception e) {

String flyfrom = (request.getParameter("flyfrom"));
String flyto = (request.getParameter("flyto"));
String name = (request.getParameter("name"));
String airline = (request.getParameter("airline"));

Date d1 = new Date(2004, 10, 25, 11, 6, 6);

/* GregorianCalendar liftOffApollo11 = new GregorianCalendar(16, 9, 32);
Date d = liftOffApollo11.getTime();
// DateFormat df2 = DateFormat.getTimeInstance(DateFormat.SHORT);
// String s2 = df2.format(d);
String s2 = request.getParameter("departuretime");
// date arrivaltime= (Integer.parseInt(request.getParameter("arrivaltime")));
int orderno = Integer.parseInt(request.getParameter("orderno").trim());
int tickets = Integer.parseInt(request.getParameter("tickets").trim());
int price = Integer.parseInt(request.getParameter("price").trim());
int total = Integer.parseInt(request.getParameter("total").trim());
int i=st.executeUpdate("INSERT INTO udetails(flyfrom,flyto,name,airline,orderno,tickets,price,total,arrivaltime,departuretime,dateofflight) VALUES('"+flyfrom+"','"+flyto+"','"+ name+"','"+airline+"',"+orderno+","+tickets+","+price+","+total +",'"+d1+"','"+d1+"','"+d1+ "')");

System.out.println("values u enetered are:" + i);
catch(SQLException e){
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
The connection String might be wrong .
The best way to solve these type of error is to write some debug statements to a file or to a console and check the exact line that gives the exception..

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

It looks like you have posted the same question twice. Please try not to do this, it creates duplicate conversations and wastes the time of the people trying to help you. I'm closing this thread, anyone who wants to help should see the thread here.

I agree. Here's the link:
subject: servlets
It's not a secret anymore!