Hi all,
I am writing a simple method which when entered with an Int parameter performs an sql query, creates a result set, uses that resultset to get values from the object created by another method and display the result as an arraylist. The method and the object are as below:
public static ArrayList getProjects(int userID)
throws SQLException, Exception
{
ArrayList arrayList = null;
getProjectsStmt .setInt(1, userID);
ResultSet rs = getProjectsStmt .executeQuery() ;
arrayList = new ArrayList();
try
{
while (rs.next())
{
Projects p = createProject(r s);
arrayList.add(p );
rs.close();
}
}
catch(Exception e)
{
System.err.prin tln(e);
}
return arrayList;
}
//Query is as follows
private static final String GET_PROJECTS_ST MT = "SELECT projectID, name FROM project WHERE userID = ?";
//createProject method that creates the Project object is as below
private static Projects createProject(R esultSet rs)
throws SQLException, Exception
{
int projectID = rs.getInt("proj ectID");
int userID = rs.getInt("user ID");
String name = rs.getString("n ame");
String description = rs.getString("d escription");
int createdate = rs.getInt("crea tedate");
boolean visibility = rs.getBoolean(" visibility");
return new Projects(projec tID, userID, name, description, createdate, visibility);
}
When i try and run this method in main to test it, i.e. getProject(1); the entry 1 exists in database and the results of the query also exists but I still get the error saying java.lang.NullP ointerException
It points to the following lines:
getProjectsStmt .setInt(1, userID); - line 6 in the getProjects method - above
getProject(1) - in main where I try to test it
Any ideas why???
Thanks,
dev
1 5337
Hi all,
I am writing a simple method which when entered with an Int parameter performs an sql query, creates a result set, uses that resultset to get values from the object created by another method and display the result as an arraylist. The method and the object are as below:
public static ArrayList getProjects(int userID)
throws SQLException, Exception
{
ArrayList arrayList = null;
getProjectsStmt .setInt(1, userID);
ResultSet rs = getProjectsStmt .executeQuery() ;
arrayList = new ArrayList();
try
{
while (rs.next())
{
Projects p = createProject(r s);
arrayList.add(p );
rs.close();
}
}
catch(Exception e)
{
System.err.prin tln(e);
}
return arrayList;
}
//Query is as follows
private static final String GET_PROJECTS_ST MT = "SELECT projectID, name FROM project WHERE userID = ?";
//createProject method that creates the Project object is as below
private static Projects createProject(R esultSet rs)
throws SQLException, Exception
{
int projectID = rs.getInt("proj ectID");
int userID = rs.getInt("user ID");
String name = rs.getString("n ame");
String description = rs.getString("d escription");
int createdate = rs.getInt("crea tedate");
boolean visibility = rs.getBoolean(" visibility");
return new Projects(projec tID, userID, name, description, createdate, visibility);
}
When i try and run this method in main to test it, i.e. getProject(1); the entry 1 exists in database and the results of the query also exists but I still get the error saying java.lang.NullP ointerException
It points to the following lines:
getProjectsStmt .setInt(1, userID); - line 6 in the getProjects method - above
getProject(1) - in main where I try to test it
Any ideas why???
Thanks,
dev
Thanks a lot for the help but after few sleepless hours got the error of my stupid ways... i dont want diagram, project or user objects just plain result sets added to arrayList which is simple as 1, 2, 3!!
Thanks for your help man...
Sign in to post your reply or Sign up for a free account.
Similar topics |
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)
int main()
{
try{
int* p = NULL;
*p = 4;
|
by: Alexander Behnke |
last post by:
Hello,
I am currently facing a problem with a calloc function call which
returns a NULL pointer while in a debugging environment. If I start the
same executable from the shell (not via the debugger) a valid pointer is
returned.
The call stack looks like this:
FlowPRESS.exe!strcat() Line 169 Asm
|
by: dev24 |
last post by:
Hi all,
I am writing a simple method which when entered with an Int parameter performs an sql query, creates a result set, uses that resultset to get values from the object created by another method and display the result as an arraylist. The method and the object are as below:
public static ArrayList getProjects(int userID)
throws SQLException, Exception
{
ArrayList arrayList = null;
getProjectsStmt.setInt(1, userID);
|
by: bevis |
last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you can.
I'm using Eclipse 3.2.2 and I have installed mysql-connector-java-5.0.6-bin.jar. I am trying to connect to SQL Enterprise Manager version 8.0 innstall on a Windows 2003 Server Enterprise Edition.
I have been able to successfully test...
|
by: ajos |
last post by:
hi evrybdy,
the problem is:-
i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem...
when i enter values in the 2 text boxes and click enter an exception occours which is-
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
| |
by: star111792 |
last post by:
helo all
i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i am getting the following exception:
type Exception report
message
|
by: neuraljay |
last post by:
hi everyone. I am trying to build a jsp using webwork, hibernate and mysql. And right now I am doing its unit testing. Everytime I run the test I am getting this error:
Error JDBC exception on Hibernate data access; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access; nested exception is...
|
by: iamdennisthomas |
last post by:
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;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |