Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
    Bookmark Topic Watch Topic
  • New Topic

servlets  RSS feed

Posts: 14
  • Mark post as helpful
  • send pies
  • Report post to moderator
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){
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Report post to moderator
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..
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!