Home Answers Viewqa Swing-AWT How to show multiple identicle rows from database on clicking search button to jtable

 
 


vikas pandey
How to show multiple identicle rows from database on clicking search button to jtable
1 Answer(s)      10 months ago
Posted in : Swing AWT

Hello Sir, I made search button with textfield .when i enter search value in the search field only one row is displayed in the jtable .Suppose i enter name in search field which has two rows in the database table so i want to display both or any number of identicle rows in the jtable .I am posting my code .plz see and give me the remaning code .

Will always be gratefull. Waiting for ur reply .Thanks

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

class Search {

public static void main(String[] args) {
    JLabel lab = new JLabel("Enter Name:");
    final JTextField t = new JTextField(20);
    JButton b = new JButton("Search");
    JPanel p = new JPanel(new GridLayout(1, 1));
    p.add(lab);
    p.add(t);
    p.add(b);
    JFrame f = new JFrame();
    f.getContentPane().add(p);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setLocationRelativeTo(null);
    f.pack();
    f.setVisible(true);

    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String name = t.getText();
            try {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/techsoft", "root", "techsoft");
                Statement st = con.createStatement();
                ResultSet rs = st.executeQuery("select * from ankur where name='" + name + "'");
                String n = "", add = "", contact = "", email = "";

                if (rs.next()) {
                    n = rs.getString("name");
                    add = rs.getString("address");
                    contact = rs.getString("contactNo");
                    email = rs.getString("email");
                }
                String data[][] = new String[1][4];
                data[0][0] = n;
                data[0][1] = add;
                data[0][2] = contact;
                data[0][3] = email;
                JFrame frame = new JFrame();
                String labels[] = {"Name", "Address", "Contact No", "Email"};
                JTable table = new JTable(data, labels);
                JScrollPane pane = new JScrollPane(table);

                frame.add(pane);
                frame.setSize(500, 100);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                //frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                // frame.pack();

            } catch (Exception ex) {
                System.out.println(e);
            }
        }
    });
}

}

View Answers

July 11, 2012 at 12:11 PM


Here is a code that search the data from the database and show multiple identical rows from database on clicking search button to jtable.

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

class Search{
    public static void main(String[] args) {
        final Vector columnNames = new Vector();
        final Vector data = new Vector();

        JLabel lab=new JLabel("Enter Name:");
        final JTextField t=new JTextField(20);
        JButton b = new JButton("Search");
        JPanel p = new JPanel(new GridLayout(2,2));
        p.add(lab);
        p.add(t);
        p.add(b);
        JFrame f = new JFrame();
        f.getContentPane().add(p);
        f.pack();
        f.setVisible(true);

        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String name=t.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 data where name='"+name+"'");
           ResultSetMetaData md = rs.getMetaData();
            int columns = md.getColumnCount();
            for (int i = 1; i <= columns; i++) {
            columnNames.addElement( md.getColumnName(i) );
            }
            while (rs.next()) {
            Vector row = new Vector(columns);
            for (int i = 1; i <= columns; i++){
            row.addElement( rs.getObject(i) );
            }
            data.addElement( row );
           }
           JFrame frame=new JFrame();
           JTable table = new JTable(data, columnNames);

           JScrollPane pane=new JScrollPane(table);

            frame.add(pane);
            frame.setVisible(true);
            frame.pack();
            }
            catch(Exception ex){
            System.out.println(e);
            }
          }
        });
    }
}









Related Pages:
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button... and show multiple identical rows from database on clicking search button... in the jtable .Suppose i enter name in search field which has two rows in the database
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button... and show multiple identical rows from database on clicking search button... in the jtable .Suppose i enter name in search field which has two rows in the database
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button... and show multiple identical rows from database on clicking search button... in the jtable .Suppose i enter name in search field which has two rows in the database
Show multiple identical rows into JTable from database
rows from database on clicking search button to jtable. The given code accepts...Show multiple identical rows into JTable from database In this tutorial, you will learn how to display the multiple rows from database to JTable. Here
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button... not figure out how to. I used DefaultTableModel but wasnt able to insert a row
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... where i have to show the search result in the same panel of where search field... JTextField(20); JButton b = new JButton("Search"); final JTable table=new
jtable displays search results
jtable displays search results   hi sir can u send me full source code for displaying search results into jtable from database n jtable n search button must be within same frame but in different Panel and the size of the frame
Hide text by clicking button
Hide text by clicking button In this tutorial, we will discuss about hide/show text by clicking on button. In the below example, there are two buttons : hide and show .The "hide " button is used to hide text and "show
search filter and JTable
my question is: how can i make search data in JTable of java? i wan to search... this in mysql, so I do not interface desktopapplication I have a button called search, but the button is called I put the code: search demo = new search
JTABLE Issue
on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search button " on a frame , by clicking this search button data will be retrived from DB... frame which gets open on click of search button. this JTable also has a back button
how to search the string arraylist contains database rows?
how to search the string arraylist contains database rows?  i need to search 2 database. one is excel database and another is SQL database. stored the row values into string arraylist. now i want to print the common rows existed
Toggle hide/show by clicking same button
Toggle hide/show by clicking same button In this tutorial, we will discuss about how to toggle hide/show by clicking button. In the given below 2 example, there is button ,by clicking on it, the paragraph will hide/show . In first
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update... rowToDelete){ // Mark row for a SQL DELETE from the Database
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update... rowToDelete){ // Mark row for a SQL DELETE from the Database
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts.... Problem.: When m clicking my next button it is not showing another question from "cards" table. passing parameter from viewalllists.jsp to flashPage.jsp
How to show next question from database on the click of next button..(Struts & Hibernate)
How to show next question from database on the click of next button..(Struts.... Problem.: When m clicking my next button it is not showing another question from "cards" table. passing parameter from viewalllists.jsp to flashPage.jsp
How to Display Next question from database after clicking Next Button using "Arraylist concept"
How to Display Next question from database after clicking Next Button using "Arraylist concept"  </tr> <%if (pageName.equals("1")) {%> <tr> <td> <div style
Get specific item details by clicking on hyperlink
and corresponding image with a hyperlink on it from the database to a jsp page. -If I click on the image or item name I should get total datails from the database...Get specific item details by clicking on hyperlink  sir, I am
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
submit button should show the user various textfields on the same panel from...How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application  Hello Sir, first of all
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
submit button should show the user various textfields on the same panel from...How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application  Hello Sir, first of all
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
submit button should show the user various textfields on the same panel from...How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application  Hello Sir, first of all
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
How to read and retrieve jtable row values into jtextfield on clicking... application in which i have to display database records in jtable .now I want... that in textfield below the jtable. plz sir give me the code.... Thank you Sir
How to update,Delete database values from jtable cells ..
How to update,Delete database values from jtable cells ..  hello Sir... from database into jtable of a jpanel.. Now Sir, According to my need i have to update the cell values from there only means that whatever values i ma entering
Getting the Number of Rows and Columns in JTable
will learn how to get the number of rows and columns in JTable.  This program simply helps us for getting the number of rows and columns from the JTable by using... Getting the Number of Rows and Columns in JTable 
multiple keyword search - SQL
and city and click search button or user may type in country and genderand click search button or user may type in country and age and click search button user may type in country and city and age and gender click search button user
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's... 10 records in the database the rows should increase with the data. i want
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  Hello Sir, I have developed a swing application in which database table... ,update,delete database values from jtable only so i added three buttons add
How to delete and update from Jtable cell in swing app
How to delete and update from Jtable cell in swing app  Hii Sir, I am developing a swing app for adding,updating and deleting from jtable... is getting removed from the jtable but selected row is getting deleted from
search from database
search from database  DBUtil util = new DBUtil(); try...); }   i want to retrieve values from database and display them in my... it show error what to do please help
storing details in database on clicking submit button - JSP-Servlet
database on clicking submit button. I am unable to do this.Can u tell me how to code...storing details in database on clicking submit button  I am using JSP in NetBeans and have developed an application form which has fileds naming
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... application i need to show search results in the same panel of jframe to where search field and button is present . please Sir, send me the code
Search data from database - Java Beginners
to user name. (means search all field from database and display using...Search data from database  Hi Deepak, This is not correct code... with two button search and delete. 2:- User input name(with alphabetical
how update JTable after adding a row into database
classes, listed below, one is table model, and second show data from database in JTable, and it's OK, but after adding a row into database table does't update. How... which shows data in JTable from database import java.awt.*; import
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JSP edit multiple rows
JSP edit multiple rows In this tutorial, you will learn how to update multiple records at the same time. The given example retrieves the record from... and allow the user to edit that particular record. User can edit multiple rows from
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ...); } DBOperations is a class for fetching data from database table...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ...); } DBOperations is a class for fetching data from database table...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new
How to add a columns with a button set to a Jtable built with database result set
How to add a columns with a button set to a Jtable built with database result... that button column to the table which is built with database result set. i would thank..., there should be another button to get further details of a account such as transactions
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  ... an entry suppose 'title' from dropdownlist and give a title name 'partial dif' in textbox and click on search button it should show me all the title names
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
Hide/Show paragraph by button click
Hide/Show paragraph by button click In this tutorial, we will discuss about how to hide/show paragraph by clicking on button using jQuery. In the below... displays another button "click to show paragraph " .when we click
PHP SQL Search
text  and choose a option from select box. The click on search button helps the user to show the records details based on search text put by the user...; PHP SQL Search is used to return the records details from the table based
insert rows from browsed file to sql database
insert rows from browsed file to sql database  i need to insert rows from excel to database by browsing the file in jsp. by connecting both..., content of the file has to go to database. how can i insert record into database

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.