Results 1 to 2 of 2
  1. #1
    Mamouz is offline Member
    Join Date
    Dec 2013
    Rep Power

    Default Swing database problem?

    Hello.i am new in java, i have created simple GUI on Eclipse, but i failed to insert data into MS Access database
    and below is my code (I need your help plz)

    package semasygui.views;

    import java.sql.*;

    import java.awt.BorderLayout;
    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.TitledBorder;
    import java.awt.Color;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.JLabel;
    import java.awt.Font;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import java.awt.Toolkit;
    import javax.swing.LayoutStyle.ComponentPlacement;

    public class BidhaaMpya extends JFrame {

    private JPanel contentPane;
    private JTextField namba;
    private JTextField jina;
    private JTextField idadi;
    private JTextField bei;

    * Launch the application.
    public static void main(String[] args) {

    EventQueue.invokeLater(new Runnable() {
    public void run() {

    try {
    BidhaaMpya frame = new BidhaaMpya();
    } catch (Exception e) {

    * Create the frame.
    public BidhaaMpya() {
    setTitle("Bidhaa Mpya");
    setIconImage(Toolkit.getDefaultToolkit().getImage( BidhaaMpya.class.getResource("/semasygui/resouces/img/sw3.png")));
    setBounds(100, 100, 620, 413);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    JPanel panel = new JPanel();
    panel.setBorder(new TitledBorder(null, "Bidhaa Mpya", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 255)));
    panel.setBounds(10, 11, 584, 352);

    JLabel lblNewLabel = new JLabel("Namba ya Bidhaa:");
    lblNewLabel.setForeground(new Color(128, 128, 128));
    lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 12));

    JLabel lblJinaLaBidhaa = new JLabel("Jina la Bidhaa:");
    lblJinaLaBidhaa.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblJinaLaBidhaa.setForeground(new Color(128, 128, 128));

    JLabel lblIdadiYaBidhaa = new JLabel("Idadi ya Bidhaa Hii:");
    lblIdadiYaBidhaa.setForeground(new Color(128, 128, 128));
    lblIdadiYaBidhaa.setFont(new Font("Tahoma", Font.BOLD, 12));

    JLabel lblBeiYaKununulia = new JLabel("Bei ya Kununulia:");
    lblBeiYaKununulia.setForeground(new Color(128, 128, 128));
    lblBeiYaKununulia.setFont(new Font("Tahoma", Font.BOLD, 12));

    namba = new JTextField();

    jina = new JTextField();

    idadi = new JTextField();

    bei = new JTextField();

    JButton btnTumaFumu = new JButton("Tuma Fumu");
    btnTumaFumu.setIcon(new ImageIcon(BidhaaMpya.class.getResource("/semasygui/resouces/img/ok.png")));
    btnTumaFumu.setFont(new Font("Tahoma", Font.BOLD, 14));
    btnTumaFumu.setForeground(new Color(0, 0, 255));

    JButton btnGhairi = new JButton("Ghairi");
    btnGhairi.setIcon(new ImageIcon(BidhaaMpya.class.getResource("/semasygui/resouces/img/delete.png")));
    btnGhairi.setForeground(new Color(0, 0, 255));
    btnGhairi.setFont(new Font("Tahoma", Font.BOLD, 14));
    GroupLayout gl_panel = new GroupLayout(panel);
    .addGroup(gl_panel.createParallelGroup(Alignment.T RAILING)
    .addGroup(gl_panel.createParallelGroup(Alignment.L EADING)
    .addComponent(idadi, 136, 136, 136)
    .addGroup(gl_panel.createParallelGroup(Alignment.L EADING, false)
    .addComponent(namba, GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
    .addContainerGap(86, Short.MAX_VALUE))
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(namba, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE))
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(jina, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(idadi, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(bei, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)


    and here is my GUI
    Swing database problem?-gui.jpg

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Swing database problem?

    Please don't hijack someone else's thread.
    Threads are I've moved your post to its own one.

    When posting code please wrap your code in [code] tags [/code].
    It's almost impossible to follow the flow of unformatted code.

    Even so, I cannot see anywhere in that code where you are even attempting to add anything to a database.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 8
    Last Post: 02-24-2012, 10:46 AM
  2. Replies: 2
    Last Post: 02-07-2012, 04:32 PM
  3. Uploading a image to a database via swing
    By hacker9116 in forum JDBC
    Replies: 3
    Last Post: 03-29-2011, 11:35 AM
  4. Getting and Displaying Swing Components From DataBase
    By vivekkumar in forum AWT / Swing
    Replies: 1
    Last Post: 07-27-2010, 03:32 PM
  5. how to insert sql file into database using swing
    By in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 04:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts