but how do we execute the SQLs. Rather how do we attach buttons on the GUI with the SQLs so that they execute smoothly.
To respond to actions, selections, etc...register the appropriate listener to perform any tasks - in the case of a JButton register an ActionListener:
How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
I also attempted at writing the SQLs into java code. This works for simple SQLs (one line statements), but not for nested / conditional SQLs.
Issues are hard/impossible to diagnose without knowing what you mean by this. Does the code compile? Are exception's thrown at runtime? Does it misbehave?