GeeCON Prague 2014*
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
Author

servlets

aparna rudra
Greenhorn

Joined: Apr 06, 2004
Posts: 14
hii
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.

thanks

package spackage;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
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 {
try{
super.init(sc);
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:appy");
st = con.createStatement();
}
catch(Exception e){
e.printStackTrace();
}
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try{
response.setContentType(CONTENT_TYPE);


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

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);
//System.out.println(s2);
String s2 = request.getParameter("departuretime");
// date arrivaltime= (Integer.parseInt(request.getParameter("arrivaltime")));
//("<response.getParametr("name")>");*/
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){
e.printStackTrace();
}
}
}
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
Rancher

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.

Dave
 
GeeCON Prague 2014
 
subject: servlets