When I took the text typed in the search bar and clicked the search button, I tried to bring up the id opposite this search text in the database. But I got an error. The query is working correctly.I'm trying to get a value of 4 like in this photo. I showed the error I got, that my query is running in the database and what happens when the search button is clicked.
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String searchKey = txtSearch.getText().toLowerCase();
Connection connection;
DbHelper dbHelper = new DbHelper();
connection = dbHelper.getConnection();
ResultSet resultSet;
PreparedStatement statement =null;
String sql ="select * from cities where city_name = '"+searchKey+"'";
System.out.println(sql);
resultSet= statement.executeQuery(sql);
int id = resultSet.getInt("city_id");
System.out.println(id);
model = (DefaultTableModel)tblcinema.getModel();
model.setRowCount(0);
ArrayList <Sinemalar> sinemalar = getSinemalar(id);
for (Sinemalar sinema : sinemalar){
Object [] row={sinema.getCinema_id(),sinema.getCinema_name(),sinema.getCinema_adress()};
model.addRow(row);
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
run:
select * from cities where city_name = 'denizli'
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Uye.Anasayfa.jButton2ActionPerformed(Anasayfa.java:308)
at Uye.Anasayfa$3.actionPerformed(Anasayfa.java:123)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6401)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2764)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 11 seconds)