About java and JDBC



Share on Google+Share on Google+

About java and JDBC
2 Answer(s)      5 years and 9 months ago
Posted in : 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();
        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();
            if (x > 6)
                button[x].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        day = button[selection].getActionCommand();
            if (x < 7) {
        JPanel p2 = new JPanel(new GridLayout(1, 3));
        JButton previous = new JButton("<< Previous");
        previous.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
        JButton next = new JButton("Next >>");
        next.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
        d.add(p1, BorderLayout.CENTER);
        d.add(p2, BorderLayout.SOUTH);

    public void displayDate() {
        for (int x = 7; x < button.length; x++)
        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);
        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


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));
        final JFrame f = new JFrame();
        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();
           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;
           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);

            catch(Exception ex){}


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
about value taken in java database - JDBC
about value taken in java database  how to take value from Serial port communication Hyperterminal to the java database
about jdbc - JDBC
about jdbc  Hello folks, I am very new JDBC. I am doing a project on java messaging service on the part of the project we are using JDBC. In my project i am having two tables one is"person" table and other is"student" table  
about jdbc - JDBC
about jdbc  Hi folks, my previous question was when "i have a table with primary key then when i enter a value which is already there will cause a problem how to solve it." i know to retrieve all the attributes
About springs - JDBC
About springs  Hi, My xml code is as follows :In this i have my id stored in results1(in tag). And now
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  What is JDBC
About java
About java   how we insert our database data into the jTable in java... in java   Hi Friend, Try the following code: import java.io.*; import...("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st
Java JDBC   Is the JDBC-ODBC Bridge multi-threaded
Java - JDBC
Java and JDBC programming  Need to learn the kills to develop the application using java and 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
Java JDBC  What is the fastest type of JDBC driver
Java JDBC  How to make pagination using JDBC
get information about foreign keys - JDBC
get information about foreign keys  How to get the information about foreign keys in Java
java - JDBC
these driver manager classes are belongs to Jdbcapi,What about Odbc?  Hi friend, The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge
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  hello, i have oracle 8i,i am a java-learner, i would like to run a jdbc programs. please tell me the steps how to run the jdbc program  For the complete reference and tutorial on Java Database Connectivity visit
JDBC batch insert using Java bean class
In this tutorial, you will learn about JDBC batch insert using java bean / model class
java - JDBC
automatically loaded. The driver is loaded by calling the Class.forName() method. JDBC drivers are designed to tell the DriverManager about themselves automatically when... on JDBC visit to : http://www.roseindia.net/jdbc/understanding-driver
java - JDBC
have to use JDBC and oracle. plz send the details for connecting "java... sending data inserting code into database using JDBC with jsp... for database connectivity: http://www.roseindia.net/jdbc/jdbc-mysql
java servlets jdbc - JDBC
java servlets jdbc  i am running the servlet program with jdbc connections in this porgram i used two 'esultset' objects.. in this wat ever coding is available in the first resultset is executed like updating and retrieiving
java - JDBC
java  how to get connectoin to database server from mysql through java programme  Hi Friend, Please visit the following link for more detailed information http://www.roseindia.net/jdbc/jdbc-mysql
JAVA(JDBC)  Hello friends, please tel me, how can we retrieve..."; String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql... for more information. http://www.roseindia.net/jdbc/save_image.shtml
Java JDBC  Is JDBC-ODBC bridge multi-threaded?  NO. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls made.... The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls
java jdbc
java jdbc  what is a prepared statement?   Hi Friend, It is a pre compiled form of Statement class. It send sql statements to the database... from the given link: JDBC Tutorials Thanks
Java JDBC driver
Java JDBC driver  What is JDBC Driver
java - JDBC
java  how can i connect jdbc with oracle 9i.please give detailed procedure.  Hi Friend, Use JDBC with Oracle Follow these steps: 1) Import the following packages in your java file:*********** import
JAVA  how to store and retrieve an image in a database(ORACLE)using java or JSP?  Hi friend, I am sending you image insert code in jsp using mysql jdbc driver so please change driver name and implement
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
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE