hi all,
m new to this site and m newbee to this java thing..i have a project dnloaded from somewhere ..and now i have some problem with updating the database ..following is the

cnt=cnt+Integer.parseInt(dis.getText());
   				System.out.println(cnt);
   			  
   			 cnt=cnt+ Integer.parseInt(ent.getText());
   			 	System.out.println (cnt);					
   
  String str="update bikeinfo set stock =" + cnt + " where model='"+ gn.getSelectedItem() + "'" ;// + ";";
  
  
  System.out.println(str);
  c.stmt.executeQuery(str);
  System.out.println(str);

and this is what is i get in cmd..

30
33
update bikeinfo set stock =33 where model='rx4'
java.lang.NullPointerException
        at Stock.actionPerformed(Stock.java:169)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
95)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6038)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
        at java.awt.Component.processEvent(Component.java:5803)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4410)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2429)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

i also tried some alternate ways to write the same thing

cnt=cnt+Integer.parseInt(dis.getText());
   				System.out.println(cnt);
   			  
   			 cnt=cnt+ Integer.parseInt(ent.getText());
   			 	System.out.println (cnt);					
   c.stmt=c.conn.prepareStatement("update bikeinfo set stock=? where model=?");
				c.stmt.setInt(12,cnt);
			
				c.stmt.setString(1,(String)gn.getSelectedItem());
				System.out.println ("after update");
c.stmt.executeQuery()

but even for this it shows error of arrayoutofboundsexception...
plz guys help this new bee..;):)

In the first case you posted, either "c" or "stmt" is probably null

c.stmt.executeQuery(str);

In the second part, you only have two parameters specified in the query, so you can't set number 12

c.stmt.setInt(12,cnt);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.