M just an infant to java..just kno the ABC.. m tryin to work in small projects like address book...so can i get help like how to start...

Do you have design your project?
First you have to design your project, then you will go to codding otherwise not.
Project design means - just design yor system in your paper and plane what you want to do in this project.
Post the details.

Oh! You also dont mention which database software you will use.My SQL seems to me much easy to handle from Java.You can use file also.But database server is much better because it is easy to use.Choice is yours.

JamesCherrill is right.
Read this . It will help you a lot.
Thank you.

Edited 5 Years Ago by peter_budo: Multi posting merge

Hey everyone..thanks for the prompt reply..so this project is a typical Address Book which can add, delete sort, search contacts..thats it..its my first one. And ye the I would work wid SQL already done in college so that would be comfartable..so how do I proceed next.

Easiest SQL to work with is the Java DB that is bundled with JDK 6 and later.
What next?
Listen to Anuradha Mandal, and design on paper before starting any code.

Although you can start with the GUI, 99% of the time this is a bad idea because it leads to an implementation with too much data and logic embedded in the GUI. Normal "best practice" is to design on paper, then implement a class or classes for your address book's data and logic, test those using some hard-coded calls and print statements, then finally build your GUI on top of that. Google MVC (model-view-controller) for more discussion on why this is a good way to structure programs.

And Anuradha...I would be using JDK 6..will get back with the code asap

Hi...onlineshade... I have the basic design..will be using JDK 6...2day is weekend so will be writing the code..mon to fri m busy in sad office...so will get back today itself with the code

hey everyone..i got this code written...but whatever i do..m not able to save the records in the database...there are no compilation errors showing up but i m not getting whats going wrong...so please guys help me out asap...

actually the entire program is running fine...but when it comes to inserting records into the MS access table it shows no errors but the data is not reflected in the database. what can be the problem

Write a JAVA program to accepts the details od Doctor from the user and insert into the database
(Use Prepared Statment class and AWT).

import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.*;

class slipfive extends JFrame implements ActionListener

  {
	
     	JLabel lno,lname,lsalary;
     	JTextField tno,tname,tsalary;
     	JButton insert,exit;

	Connection cn;
        Statement st;
	ResultSet rs;
	Container conpane;

	slipfive()
	
	{
		
		lno=new JLabel("Dno");
		lname=new JLabel("Dname");
		lsalary=new JLabel("Dsalary");

		tno=new JTextField(6);
		tname=new JTextField(15);
		tsalary=new JTextField(15);

		insert=new JButton("Insert");
		exit=new JButton("Exit");

		conpane=getContentPane();

		JPanel txtPanel,btnPanel;

		txtPanel=new JPanel();
		btnPanel=new JPanel();

		conpane.add(txtPanel,BorderLayout.NORTH);
		conpane.add(btnPanel,BorderLayout.CENTER);

		txtPanel.add(lno);
		txtPanel.add(tno);

		txtPanel.add(lname);
		txtPanel.add(tname);

		txtPanel.add(lsalary);
		txtPanel.add(tsalary);

		btnPanel.add(insert);
		btnPanel.add(exit);

		insert.addActionListener(this);
		exit.addActionListener(this);

		try
		
			{

				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

				cn=DriverManager.getConnection("jdbc:odbc:myaddressbookdsn");
				st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				rs=st.executeQuery("select * from doc");
		
			}catch(Exception e){}
		
		}

		public void actionPerformed(ActionEvent a)
	
		{
		
			try
		
			{
				
				if(a.getSource()==insert)
				{
					int dno=Integer.parseInt(tno.getText());
					String name=(tname.getText());
					int salary=Integer.parseInt(tsalary.getText());
			
					st.executeUpdate("insert into doc values("+dno+",'"+name+"',"+salary+")");
					JOptionPane.showMessageDialog(null,"Record inserted into database");

					dbClose();
					dbOpen();
				}
				
				if(a.getSource()==exit)
				{
					if(JOptionPane.showConfirmDialog(null,"Are You Sure You Want To Exit?","Confirm",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
					System.exit(0);
				}
			
			}catch(Exception e){}

		}

public void dbOpen()

	{
		try
	
			{
			
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


		     	cn=DriverManager.getConnection("jdbc:odbc:myaddressbookdsn");
		     	st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
		        rs=st.executeQuery("select * from doc");
		        rs.next();

		        }catch(Exception e){}
	}



public void setText(){
		try{
			tno.setText(rs.getString(1));
            		tname.setText(rs.getString(2));
			tsalary.setText(rs.getString(3));
	    	}catch(Exception ex){}
	    	}


	    	public void dbClose()
				{
					try{
					st.close();
					rs.close();
					cn.close();
					}catch(Exception e){}
	}

}

class slip5
{
	public static void  main(String s[])
	{
		slipfive f= new slipfive();
		f.setVisible(true);
		f.setTitle("Doctor Information");
		f.setSize(450,350);
	}

}

This is my basic code for insertion of records....please do tell me where i m going wrong

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

It's easy.Design the interface by using jFrame form.Then start to coding.Insert,Delete,Update are also easy.You can use stacks or ques.Then sorting part also easy.Use one of insertion,selection,merge sort algorithms...:)

hey pro_learner....i did the whole coding part and its working fine..but the real problem lies in the database...the record are not reflecting in the MS Access database when i insert one...so what shud b done here?

Design the interface by using jFrame form.

taga1989's code is may be a Jframe code in Java swing as he used import javax.swing.*;

You would have a much better idea of why it wasn't working if you did not do this

}catch(Exception e){}

At least print a stack trace of the exception.

}catch(Exception e){
  e.printStackTrace();
}

M just an infant to java..just kno the ABC.. m tryin to work in small projects like address book...so can i get help like how to start...

Good that you came into the java world. It is not so difficult to work with java. As you want to develop an application, i would say , you must first know the core java. And make use of swing components. That would be nice to look and feel . Thank you.

This article has been dead for over six months. Start a new discussion instead.