473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Null pointer exception

Hi Guys i was developing a action servlet which is actulally getting the data from a form and putting it in the db but while executing i am getting a null pointer exception

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.radesan.struts.action;

import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.radesan.struts.form.NewAdminForm;

/**
* MyEclipse Struts
* Creation date: 03-09-2008
*
* XDoclet definition:
* @struts.action path="/newAdmin" name="newAdminForm" input="/newadmin.jsp" scope="request"
* @struts.action-forward name="success" path="/admin.jsp"
*/
public class NewAdminAction extends Action {
/*
* Generated Methods
*/
int j;
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
NewAdminForm newAdminForm = (NewAdminForm) form;// TODO Auto-generated method stub
int staffnumber=0;
try {
Connection cn=null;
Statement s=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:radesan" );
s=cn.createStatement();
rs=s.executeQuery("select max(staffnumber) from newadmin");
if(rs.next()) {
staffnumber=rs.getInt(1);
}
rs.close();
s.close();
cn.close();
}catch(Exception e) {e.printStackTrace();}

String bloodgroup;
String dateofjoining;
try {
Connection cnn=null;
Statement cs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cnn=DriverManager.getConnection("jdbc:odbc:radesan ");
String sno = Integer.toString(++staffnumber);

bloodgroup=newAdminForm.getB1()+newAdminForm.getB2 ();
dateofjoining=newAdminForm.getDd()+"/"+newAdminForm.getMm()+"/"+newAdminForm.getYy();
String insert="insert into newadmin values ('"+sno+"','"+newAdminForm.getFirstname()+"','"+ne wAdminForm.getLastname()+"','"+newAdminForm.getPas sword()+"','"+newAdminForm.getAuthorisation()+"',' "+newAdminForm.getStreet()+"','"+newAdminForm.getS tate()+"','"+newAdminForm.getPincode()+"','"+newAd minForm.getSex()+"','"+bloodgroup+"','"+newAdminFo rm.getAge()+"','"+newAdminForm.getLandline()+"','" +newAdminForm.getMobile()+"','"+dateofjoining+"',' "+newAdminForm.getSTATUS()+"')";
j=cs.executeUpdate(insert);
cs.close();
cnn.close();


}catch(Exception e){e.printStackTrace();}
return mapping.findForward("success");
}
}
Apr 5 '08 #1
5 2323
JosAH
11,448 Expert 8TB
Hi Guys i was developing a action servlet which is actulally getting the data from a form and putting it in the db but while executing i am getting a null pointer exception
Don't make us guess; the JVM does not simply say "null pointer exception,
bad luck", it also gives you the line number and the text of the line where that
exception was thrown; on top of that it gives you the entire stack trace.

I don't think it is too much to ask if you reproduce all that information for us here
if you want us to solve your problem.

kind regards,

Jos
Apr 5 '08 #2
sukatoa
539 512MB
Don't make us guess; the JVM does not simply say "null pointer exception,
bad luck", it also gives you the line number and the text of the line where that
exception was thrown; on top of that it gives you the entire stack trace.

I don't think it is too much to ask if you reproduce all that information for us here
if you want us to solve your problem.

kind regards,

Jos
And i agree........

sukatoa
Apr 5 '08 #3
pronerd
392 Expert 256MB
Please use code tags when posting code.

It looks like the Statement object is never initialized. So the executeUpdate() method is being called on a a null object.
Apr 7 '08 #4
hsn
237 100+
can you print the code again using the CODE tags it will be much simpler to read.

good luck

hsn
Apr 8 '08 #5
BigDaddyLH
1,216 Expert 1GB
That's one wide line ;-)
Apr 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
5
by: Boniek | last post by:
Hi I define a public property in a new form and I can see this property in table of Properties in Visual. How I can hide this property to see only in code ? Thank's Boniek
5
by: Tony Cheng | last post by:
for (int i=0; i<_request.Form.Count; i++ ) { string key = _request.Form.GetKey(i); if ( !key.Equals("formCode") && !key.Equals("formLanguage") && !key.Equals("__VIEWSTATE") &&...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
18
by: Denis Petronenko | last post by:
Hello, in the following code i have segmentaion fault instead of exception. Why? What i must to do to catch exceptions in such situation? Used compiler: gcc version 3.3.6 (Debian 1:3.3.6-13) ...
3
by: Michael | last post by:
Hi, Could you tell me how to under the following statements? Does it mean each and every memory allocation will check all the pointer no matter a null pointer or not? Right? Thanks in advance! ...
1
by: zahidkhan | last post by:
Hi All, Plz help me if you can..... I have a program something like this int main(int argc,char* argv) { try { int* p = NULL;
46
by: lovecreatesbea... | last post by:
Do you prefer malloc or calloc? p = malloc(size); Which of the following two is right to get same storage same as the above call? p = calloc(1, size); p = calloc(size, 1);
76
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the...
18
by: sanjay | last post by:
Hi, I have a doubt about passing values to a function accepting string. ====================================== #include <iostream> using namespace std; int main() {
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.