Results 1 to 13 of 13
Thread: search data from textfield
- 05-03-2012, 08:50 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
- 05-03-2012, 09:46 AM #2
Re: search data from textfield
Don't double post the same question, don't wake old dead threads and don't hijack another poster's thread with an unrelated question. The post you made in JTable vs JTextField - which to use for creating "Search" screen has been removed.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-03-2012, 09:47 AM #3
Re: search data from textfield
That's a very broad question. You need to break that into several steps and tell us which you know and which you don't know how to do.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-03-2012, 11:46 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Re: search data from textfield
I know about the jtable to display the data ....
but want to try for textbox....
for example : if i write a sting in text box : like a name..
the it display all the record in jtable for a particular name......
- 05-03-2012, 01:10 PM #5
Re: search data from textfield
What's a text box?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-03-2012, 01:13 PM #6
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
- 05-03-2012, 02:50 PM #7
Re: search data from textfield
Do you know how to retrieve the text from a JTextField as a String?
If you don't break this into several steps and tell us which step(s) you need help with, this is going to take forever.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-04-2012, 07:02 AM #8
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
- 05-04-2012, 07:44 AM #9
Re: search data from textfield
So, what's the next step?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-04-2012, 12:04 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: search data from textfield
So show us the JDBC code then.
Please don't make this the equivalent of getting blood from a stone.
You want help?
We need information.Please do not ask for code as refusal often offends.
- 05-04-2012, 02:29 PM #11
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Re: search data from textfield
Hey I m done it...
Hello Friends I m creating one textfield and retrive data from that textfield and display it in JTable.
This is the code for it....
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;
public class Search {
public static void main(String[] args)
{
final Vector columnNames = new Vector();
final Vector data = new Vector();
final JTextField t=new JTextField(20);
JButton b = new JButton("Search");
JPanel p=new JPanel( new GridLayout(2,2));
p.add(t);
p.add(b);
JFrame f = new JFrame();
f.getContentPane().add(p);
f.setVisible(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:person");
String sql = "select * from person where name='"+t.getText()+"'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
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 );
}
rs.close();
stmt.close();
}
catch(Exception ex){
System.out.println(ex);
}
JTable table = new JTable(data, columnNames);
TableColumn col;
for (int i = 0; i < table.getColumnCount(); i--)
{
col = table.getColumnModel().getColumn(i);
col.setMaxWidth(250);
}
JScrollPane scrollPane = new JScrollPane( table );
JFrame f1=new JFrame();
f1.add( scrollPane );
f1.setSize(600,400);
f1.setVisible(true);
} });
}
}
------------------------------------------------
Note : Here In the above code
Database Name = person
Table Name = person.
Thanx Friends
McaJavaProgramer.Last edited by mcajavaprogramer; 05-04-2012 at 02:52 PM.
- 05-04-2012, 03:21 PM #12
Re: search data from textfield
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-07-2012, 06:30 AM #13
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
Search data for a month
By victoryo in forum New To JavaReplies: 5Last Post: 12-28-2011, 05:51 PM -
Any advice - java search algorithms which accept multiple search parameters
By Alfster in forum New To JavaReplies: 4Last Post: 03-24-2011, 11:50 PM -
Getting data from textfield into another class
By aborgeld in forum New To JavaReplies: 11Last Post: 03-20-2011, 08:04 PM -
Data Structures(Binary Search Tree to AVL Tree)ASAP pls
By jfAdik in forum Forum LobbyReplies: 0Last Post: 04-04-2010, 07:40 AM -
how to search xml file data based on the given keyword from html form?
By nicemothi in forum XMLReplies: 0Last Post: 04-04-2008, 09:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks