Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at DatabaseTwo.manufacturerSearch(DatabaseTwo.java:81)
at SearchManufacturerScreen.searchForManufacturer(SearchManufacturerScreen.java:241)
at SearchManufacturerScreen.actionPerformed(SearchManufacturerScreen.java:192)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
I understand that the error code given above tells me where the null field exists however, what confuses me is that I am basically copying a program from another software engineer in an attempt to understand it better and replacing his variables with my own. The thing compiles and runs, I can enter data to the database but cannot retrieve the data.
Considering the code first specifies the DatabaseTwo class and the manufacturerSearch method i'll post the Database Two code.
I'm wondering if any of you can see the issue in this class or if it might tie to another one of the other 6 classes in this program.
For reference, line 81 is:
statement = connectionToFirePlaceDB.createStatement();
Thanks for any help
Silent
DatabaseTwo code as follows:
import java.sql.*;
public class DatabaseTwo
{
static public Connection connectionToFirePlaceDB;
static public Statement statement;
static public int loadDriver()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException exception)
{
return (-1);
}
return (0);
}
static public int makeConnectionToFirePlaceDB()
{
try
{
connectionToFirePlaceDB = DriverManager.getConnection("jdbc:odbc:FirePlace");
}
catch (SQLException exception)
{
return (-1);
}
return (0);
}
static public int closeConnection()
{
try
{
connectionToFirePlaceDB.close();
}
catch (SQLException exception)
{
return (-1);
}
return (0);
}
static public int writeToFirePlaceDB(String midIn, String mNameIn, String mContactIn)
{
String SQLString;
SQLString = "INSERT INTO MANUFACTURER VALUES ('" + midIn + "','" + mNameIn + "','" + mContactIn + "')";
try
{
statement = connectionToFirePlaceDB.createStatement();
statement.executeUpdate (SQLString);
}
catch (SQLException exception)
{
return (-1);
}
return (0);
}
static public ResultSet manufacturerSearch(String midIn, String mNameIn)
{
ResultSet rs = null;
String SQLString = null;
if (!(midIn.equals("")))
{
SQLString = "SELECT * FROM MANUFACTURER WHERE mid = '" + midIn +"'";
}
else
if (!(mNameIn.equals("")))
{
SQLString = "SELECT * FROM MANUFACTURER WHERE mName = '" + mNameIn +"'";
}
try
{
statement = connectionToFirePlaceDB.createStatement();
rs = statement.executeQuery(SQLString);
}
catch (SQLException exception)
{
return rs;
}
return rs;
}
static public int deleteManufacturer(String midIn)
{
int code;
String SQLString = "DELETE * FROM MANUFACTURER WHERE mid = '" + midIn +"'";
try
{
statement = connectionToFirePlaceDB.createStatement();
code = statement.executeUpdate(SQLString);
}
catch (SQLException exception)
{
return (-1);
}
return(code);
}
static public int upDateManufacturer(String midIn, String mNameIn, String mContactIn)
{
int code;
String SQLString = "UPDATE MANUFACTURER SET mid = '" + midIn + "', mName = '" + mNameIn + "', mContact = '" +
mContactIn +"'";
try
{
statement = connectionToFirePlaceDB.createStatement();
code = statement.executeUpdate(SQLString);
}
catch (SQLException exception)
{
return (-1);
}
return (code);
}
}
// End of class