About java and JDBC

Ads
 

About java and JDBC

Hello sir, I am doing project on java thats on swings,and using the dbase as MSSQL. what i want to know is i had created a name ,textfield ,calender(for DObirth selection), this is displayed in GUI window.

Then i had created a table of Patient name ,DOBirth fields in MSSQL.Here assume three to four names are present.Has of now i had dispalyed a table in GUI window using jdbc-odbc separate program i had written. Now what i want is after displaying only Patient name (label),and calender and search button,.By clicking the search after giving name and DOBirth, it has to display only according there respective Patient details how to achieve it sir.

Plz help me in this regard.

Thanks & Regards Pradeep CBZ

View Answers

January 9, 2012 at 1:29 PM

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

class DatePicker {
    int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
    int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
    JLabel l = new JLabel("", JLabel.CENTER);
    String day = "";
    JDialog d;
    JButton[] button = new JButton[49];

    public DatePicker(JFrame parent) {
        d = new JDialog();
        d.setModal(true);
        String[] header = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" };
        JPanel p1 = new JPanel(new GridLayout(7, 7));
        p1.setPreferredSize(new Dimension(430, 120));

        for (int x = 0; x < button.length; x++) {
            final int selection = x;
            button[x] = new JButton();
            button[x].setFocusPainted(false);
            button[x].setBackground(Color.white);
            if (x > 6)
                button[x].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        day = button[selection].getActionCommand();
                        d.dispose();
                    }
                });
            if (x < 7) {
                button[x].setText(header[x]);
                button[x].setForeground(Color.red);
            }
            p1.add(button[x]);
        }
        JPanel p2 = new JPanel(new GridLayout(1, 3));
        JButton previous = new JButton("<< Previous");
        previous.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                month--;
                displayDate();
            }
        });
        p2.add(previous);
        p2.add(l);
        JButton next = new JButton("Next >>");
        next.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                month++;
                displayDate();
            }
        });
        p2.add(next);
        d.add(p1, BorderLayout.CENTER);
        d.add(p2, BorderLayout.SOUTH);
        d.pack();
        d.setLocationRelativeTo(parent);
        displayDate();
        d.setVisible(true);
    }

    public void displayDate() {
        for (int x = 7; x < button.length; x++)
            button[x].setText("");
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                "MMMM yyyy");
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.set(year, month, 1);
        int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
        int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
        for (int x = 6 + dayOfWeek, day = 1; day <= daysInMonth; x++, day++)
            button[x].setText("" + day);
        l.setText(sdf.format(cal.getTime()));
        d.setTitle("Date Picker");
    }

    public String setPickedDate() {
        if (day.equals(""))
            return day;
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.set(year, month, Integer.parseInt(day));
        return sdf.format(cal.getTime());
    }
}

January 9, 2012 at 1:29 PM

continue....

class SearchPatientInformation {
    public static void main(String[] args) {
        JLabel lab=new JLabel("Patient Name:");
        JLabel label = new JLabel("Date of Birth:");
        final JTextField t=new JTextField(20);
        final JTextField text = new JTextField(20);
        JButton b = new JButton("Search");
        JPanel p = new JPanel(new GridLayout(3,2));
        p.add(lab);
        p.add(t);
        p.add(label);
        p.add(text);
        p.add(b);
        final JFrame f = new JFrame();
        f.getContentPane().add(p);
        f.pack();
        f.setVisible(true);
        text.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent ae) {
                text.setText(new DatePicker(f).setPickedDate());
            }
        });
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String name=t.getText();
            String dob=text.getText();
            try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from patient where patientName='"+name+"' and dob='"+dob+"'");
           String n="",d="",email="",address="";
           int contact=0;
           if(rs.next()){
               n=rs.getString("patientName");
               d=rs.getString("dob");
               email=rs.getString("email");
               address=rs.getString("address");
               contact=rs.getInt("contactNo");
           }
           String data[]={n,address,Integer.toString(contact),email,d};
           JFrame f=new JFrame();
           JPanel p=new JPanel(new GridLayout(5,2));
           String labels[]={"Patient Name","Address","Contact No","Email","Date Of Birth"};
           JLabel l[]=new JLabel[5];
           JTextField text[]=new JTextField[5];
            for(int i=0;i<5;i++){
                l[i]=new JLabel(labels[i]);
                text[i]=new JTextField(20);
                p.add(l[i]);
                p.add(text[i]);
                text[i].setText(data[i]);
                text[i].setEnabled(false);
            }
            f.add(p);
            f.setVisible(true);
            f.pack();

            }
            catch(Exception ex){}
            }
        });
    }
}

Ads









Related Tutorials/Questions & Answers:
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java... in GUI window using jdbc-odbc separate program i had written. Now what i want...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
About java and JDBC
About java and JDBC  Hello sir, I am doing project on java... in GUI window using jdbc-odbc separate program i had written. Now what i want...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
Advertisements
About Java
About Java  Hi, Can anyone tell me the About Java programming language? How a c programmer can learn Java development techniques? Thanks   Hi, Read about java at http://www.roseindia.net/java. Thanks
Java JDBC
Java JDBC  How to make pagination using JDBC
JDBC ODBC Connection In Java
JDBC ODBC Connection In Java In this section we will read about the various... a bridge between the Java Programming Language and the ODBC to use the JDBC API... example which will demonstrate you about how to use the JDBC API using JDBC
JDBC batch insert using Java bean class
In this tutorial, you will learn about JDBC batch insert using java bean / model class
about java
about java  how to get the value from the user like c, c++ program pls explain with example for me
Java Jdbc
Java Jdbc  sir i want to databse(oracle 10g)connectivity through java through program   Hi Friend, Follow these steps: 1) Import the following packages in your java file: import java.sql.*; import
Java JDBC ODBC
Java JDBC ODBC  What is the difference between JDBC and ODBC
java - JDBC
Java home dir  What is the Home Directory for Java
JDBC, JAVA
JDBC, JAVA  I want to develop a s/w that will work on a LAN, so is there any need for a server, bcoz I am using database to store information, and these information will be on LAN
java - JDBC
java  How to generate a report in java like we do in vb
Java - JDBC
Java  How to Connect the java with oracle by using type2 driver? can you tell me the steps
java - JDBC
as a Boolean class instance. All of the primitive wrapper classes in Java... to : http://www.roseindia.net/java/wrapper-class/ Thanks
java - JDBC
to : http://www.roseindia.net/java/exceptions/ Thanks
Ask about java
Ask about java  Create a java program for add and remove the details of a person, which is not using by database, a simply java program. If possible, please wil it in switch case
about c and java
about c and java   i need java and c language interview and objective questions with answers for the fresher.please provide to me   Please visit the following links: http://www.roseindia.net/java/ http
Questions about Java's String pool
Questions about Java's String pool  Questions about Java's String pool
Java JSP - JDBC
Java JSP  JDBC connectivity in JSP?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml Hope that it will be helpful for you. Thanks
java,jdbc,netbeans
java,jdbc,netbeans  can you tell me the program which read multiple dbf files and then insert those dbf files data in msaccess automatically
about array in java
about array in java  speed of a vehicle is measured using the total time and the distance by using the equation given bellow speed(km/hour)=distance... Vehicle 02 = 5 hours Write a JAVA class to represent the Vehicle. The program should
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database... = "jdbc:mysql://localhost:3306/"; String db = "register"...://www.roseindia.net/jdbc
About inheritanance in JAVA
About inheritanance in JAVA  What is need foe the Inheritance in though we can access any method of any class declared publicly in simple class calling
Java Example projects about STRUTS
Java Example projects about STRUTS  Hai... I completed MCA but i have no job in my hands. But i do some small projects about STRUTS. Please send me some example projects about STRUTS.   Please visit the following link
About Java
About Java This article is discussing about Java, which is a programming language developed by James Gosling at Sun Microsystems. Java now part of Oracle... about Java is listed below : Around 1.1 billions desktop runs Java. Every
about java swing - Java Beginners
about java swing   How to upload the pictures and photo on the panel in java swing ,plz help thank a lot.  Hi Friend, Try the following code: import java.awt.*; import java.io.*; import javax.swing.*; import
Java application - JDBC
Java application  Seasons greetings, I successfully designed the Food festival application using the help rosenet team rendered but it is not exactly the specification i said.so i altered it.I thank rosenet team for their timely
excel file using JDBC java.?
excel file using JDBC java.?  hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a excel file and then appends the same... used JDBC ODBC to read from excel file. i am not able to append it using
Accessing database with JDBC via Java
Accessing database with JDBC via Java  How to access a database with JDBC via Java application?   Accessing database with JDBC through Java JDBC Example to access Database import java.sql.*; public class JdbcConnect
java- jdbc with type 4 driver
java- jdbc with type 4 driver  My program code is----- import java.sql.*; import java.lang.* ; import java .io.*; import java.util.*; import... = DriverManager.getConnection("jdbc:oracle:[email protected]:1521:XE", "system", "oracle"); Statement
How do beginners learn about Java?
How do beginners learn about Java?  Hi, I am beginner in Java and want to Java very fast. Is it possible to learn java fast? How do beginners learn about Java? Thanks   Hi, Beginners can start learning Java

Ads