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

    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();
    frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

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

    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);
    contentPane.add(panel);

    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();
    namba.setColumns(10);

    jina = new JTextField();
    jina.setColumns(10);

    idadi = new JTextField();
    idadi.setColumns(10);

    bei = new JTextField();
    bei.setColumns(10);

    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);
    gl_panel.setHorizontalGroup(
    gl_panel.createParallelGroup(Alignment.LEADING)
    .addGroup(gl_panel.createSequentialGroup()
    .addContainerGap()
    .addGroup(gl_panel.createParallelGroup(Alignment.T RAILING)
    .addComponent(lblBeiYaKununulia)
    .addComponent(lblIdadiYaBidhaa)
    .addComponent(lblJinaLaBidhaa)
    .addComponent(lblNewLabel))
    .addGap(18)
    .addGroup(gl_panel.createParallelGroup(Alignment.L EADING)
    .addComponent(idadi, 136, 136, 136)
    .addGroup(gl_panel.createParallelGroup(Alignment.L EADING, false)
    .addComponent(bei)
    .addComponent(jina)
    .addComponent(namba, GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
    .addGroup(gl_panel.createSequentialGroup()
    .addComponent(btnTumaFumu)
    .addGap(83)
    .addComponent(btnGhairi)))
    .addContainerGap(86, Short.MAX_VALUE))
    );
    gl_panel.setVerticalGroup(
    gl_panel.createParallelGroup(Alignment.LEADING)
    .addGroup(gl_panel.createSequentialGroup()
    .addGap(22)
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(lblNewLabel)
    .addComponent(namba, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE))
    .addGap(30)
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(lblJinaLaBidhaa)
    .addComponent(jina, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
    .addGap(32)
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(lblIdadiYaBidhaa)
    .addComponent(idadi, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))
    .addGap(38)
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(lblBeiYaKununulia)
    .addComponent(bei, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
    .addGap(18)
    .addGroup(gl_panel.createParallelGroup(Alignment.B ASELINE)
    .addComponent(btnTumaFumu)
    .addComponent(btnGhairi))
    .addContainerGap())
    );
    panel.setLayout(gl_panel);
    }

    }

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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Swing database problem?

    Please don't hijack someone else's thread.
    Threads are free...so 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, 09:46 AM
  2. Replies: 2
    Last Post: 02-07-2012, 03: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 ravi.virgoo@gmail.com in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 03: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
  •