I'm trying to query my database and display in a combo box. But I constantly get the same error, so Im not sure now where the problem is exactly, I get java.lang.NullPointerException everytime I click on the combobox
this is my code:
``
public Sell_Tick()
{
initComponents();
FillRouteCombo();
con = CreateDB.getConnection();
if(con!=null)
{
System.out.println("Successful DB Connection");
}
}
private void FillRouteCombo()
{
try
{
pst=con.prepareStatement("select * from routes");
rst= pst.executeQuery();
while(rst.next())
{
String getroutes=rst.getString("destfrom");
destfrom.addItem(getroutes);
}
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
The error i get is this
java.lang.NullPointerException
Successful DB Connection
at Sell_Tick.FillRouteCombo(Sell_Tick.java:47)
at Sell_Tick.<init>(Sell_Tick.java:34)
at StartPage.TicketOperationActionPerformed(StartPage.java:1710)
at StartPage.access$5300(StartPage.java:52)
at StartPage$33.actionPerformed(StartPage.java:1121)
and line 47 is pst=con.prepareStatement("select * from routes");