This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need help in this swing gui app

 
ashu nagar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am working on a project related to shopping mall billing software.....
i have to add items for this i have write this code...

this is the action perform method for add button


this is my item insert method where the bean object is passed--------



why this code is not working.....please help
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. What does "is not working" mean? What is or is not happening, and how does that differ from what you were expecting? If there's an exception, post the stack trace.

For starters, you should print out the entire DB statement before you execute it, so that you know what gets sent to the DB. I would also advise to get into the habit of using PreparedStatement instead of using interpolated strings, both for code clarity and security reasons. At a quick glance, I doubt that the INSERT statement is correct.
 
ashu nagar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
run:
java.lang.NullPointerException
at com.system.connection.ALLQUERIES.ItemInsert(ALLQUERIES.java:30)
at com.system.screen.Item.Add_Item.jButton1ActionPerformed(Add_Item.java:97)
at com.system.screen.Item.Add_Item.access$000(Add_Item.java:22)
at com.system.screen.Item.Add_Item$1.actionPerformed(Add_Item.java:77)
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:6297)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6062)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:647)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
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)





this is the exception.....
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So which one is line 30 of ALLQUERIES?

And what is the actual DB statement that is being executed, after you have assembled it?

By the way, in Java class names are generally not in all uppercase (they normally use CamelCase), and method names start with a lowercase letter. Just so your code does not confuse other people :-)
 
ashu nagar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





and the get database connection is in this class.......


 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is bad, don't ever do that:

You simply must handle exceptions, or at the very least print the stack trace to where you will see it.

Also note that you should load the DB driver only once, not repeatedly. Best to do it in a static initializer.
 
Campbell Ritchie
Marshal
Posts: 52622
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags to your post, which you should always use. Unfortunately they highligh the inconsistent indentation; you need to indent your code consistently, otherwise you can miss mistakes. You should also be careful about Capital Letters; putting capitals in the wrong place can result in obscure errors. Have a look at these suggestions.

Why are you returning a String from ItemInsert?
Another bit of bad coding is the empty catch block in the connection method. You are hiding the Exception from yourself, so you do not know whether it has been made.
Actually, I think you must not return null from that method. I think you are wrong to catch the Exception there at all. If you cannot make a connection, you should allow the Exception to propagate and catch it in the using method.
Don't make your connection a field. Don't try to create a new connection in the make statement method.
I expect this discussion will move to a databases forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!