SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem inserting data into MS Access database

    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 codeI need your help plz)

    Code Java:
    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.TRAILING)
    						.addComponent(lblBeiYaKununulia)
    						.addComponent(lblIdadiYaBidhaa)
    						.addComponent(lblJinaLaBidhaa)
    						.addComponent(lblNewLabel))
    					.addGap(18)
    					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
    						.addComponent(idadi, 136, 136, 136)
    						.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, 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.BASELINE)
    						.addComponent(lblNewLabel)
    						.addComponent(namba, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE))
    					.addGap(30)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(lblJinaLaBidhaa)
    						.addComponent(jina, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
    					.addGap(32)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(lblIdadiYaBidhaa)
    						.addComponent(idadi, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))
    					.addGap(38)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(lblBeiYaKununulia)
    						.addComponent(bei, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
    					.addGap(18)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(btnTumaFumu)
    						.addComponent(btnGhairi))
    					.addContainerGap())
    		);
    		panel.setLayout(gl_panel);
    	}
     
    }

    and here is my GUI
    GUI.jpg
    Last edited by Mittineague; Dec 6, 2013 at 16:59. Reason: reformatting bbcode tags

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2007
    Posts
    1,401
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I almost puked when I saw "swing". Anyways, I don't see any code where you are inserting data.

  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sg707 View Post
    I almost puked when I saw "swing". Anyways, I don't see any code where you are inserting data.
    yeah, let me say this i started to learn java, previous i used PHP Language and i know it well but i cant use php for standalone apps, then i started with java but am totally new in java! i created a GUI and now i need the codes for connection to my database ( *.mdb) i have created my database, now what i want is how do i connect to my access db and insert data to it when user press a button. Thanks.

  4. #4
    SitePoint Wizard
    Join Date
    Apr 2007
    Posts
    1,401
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Java is easy to learn but hard to master. The beauty of Java isn't they programming language but surrounding support library and frameworks. Here is a library for what you exactly want to do.

    http://jackcess.sourceforge.net/


Bookmarks

Posting Permissions

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