Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC JTextfields working with JTextArea

Have Programming Question? Ask it here!
 
 
 


David foley
JTextfields working with JTextArea
1 Answer(s)      a year and a month ago
Posted in : JDBC


I have 2 database tables one is history the other is patient,

How can I get which every patient is being displayed on the text fields To have their history on History table displayed on a Jtextarea


Advertisement
View Answers

March 4, 2013 at 6:57 PM


hi friend,

try the following code below :

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

import java.awt.event.*;
public class  FetchDataIntoJTextArea implements ActionListener{
    JTextField textbox = new JTextField();
    JTextArea textarea=new JTextArea(5,20); 
    JButton b=new JButton("Patient History");
    String driverName = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/record";
    String userName = "root";
    String password = "root";
    public void createUI()
    {
        JFrame f=new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
        f.setLayout(null);
        JLabel tbLabel = new JLabel("Patient Name : ");
        JLabel taLabel=new JLabel("Patient History : ");        
        b.addActionListener(this);      


        tbLabel.setBounds(10, 30, 100, 20);
        textbox.setBounds(120,30,150,20);
        taLabel.setBounds(10,60,100,20);
        textarea.setBounds(120,60,150,60);
        b.setBounds(120,130,150,20);       

        f.add(tbLabel);
        f.add(textbox);
        f.add(taLabel);        
        f.add(textarea);
        f.add(b);
        f.setVisible(true);
        f.setSize(400,300);
    }
    public static void main(String[] args){
        FetchDataIntoJTextArea dd = new FetchDataIntoJTextArea();
        dd.createUI();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        b = (JButton)e.getSource();     
        getOperation();
    }
    public void getOperation()
    {
        String textboxValue = textbox.getText();        
        try
        {
            Class.forName(driverName);
            Connection con = DriverManager.getConnection(url, userName, password);
            String sql = "select pHistory from patient where pName" +
                    " = '"+textboxValue+"'";
            PreparedStatement ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();           
            while(rs.next())
            {                  
                textarea.setText(rs.getString("pHistory"));             
            }

            JOptionPane.showMessageDialog(null, "Retrieved data succesfully." +
                    "","Record Retrieved",
                    JOptionPane.INFORMATION_MESSAGE);
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null, ex.getMessage(),"Error",
                    JOptionPane.ERROR_MESSAGE);
        }           
    }    
}


Related Tutorials/Questions & Answers:
JTextfields working with JTextArea
JTextfields working with JTextArea  I have 2 database tables one... on a Jtextarea   hi friend, try the following code below : import java.sql.... = new JTextField(); JTextArea textarea=new JTextArea(5,20); JButton b=new
jtextarea
jtextarea  how to use append function in jtextarea?? i have build an application and i have to display only particular column data which can have multiple rows.it is not working with settext but using using append the value gets
Advertisements
jtextarea
jtextarea  how to use append function in jtextarea?? i have build an application and i have to display only particular column data which can have multiple rows.it is not working with settext but using using append the value gets
jtextarea
jtextarea   How To: Add line numbers to JTextArea?? help
jTextArea
jTextArea  how to get each/all values from ms access database into jtextarea of a particular entity..??Please Help
jTextArea
jTextArea  can jtextarea have numbers like 1 will be set to default and when the user writes in first line and hits enter the 2nd number should automatically be created??can this be done in netbeans??please help
AutoCompleteField using JTextArea
AutoCompleteField using JTextArea  How to create an AutoCompleteField in java such as username field using JTextArea
JTextArea - Swing AWT
JTextArea  Dear Sir, I was hoping you could please help me on, how to restrict the maximum characters that the user can Enter in the JTextArea of my Application. I want that the User can Enter only 300 Characters, not more
How to get filename in JTextArea in following case?
How to get filename in JTextArea in following case?  Hi, i'm trying to code a GUI in java, the following code is working but the filenam is not displayed in the JTextArea, why? [CODE] private void
view data from jTextArea to jtable
view data from jTextArea to jtable  good night Please help senior java all, I want to make a brief program of reading data in the text area and then on the show to the j table. I created a new scrip like below but it does
JTextArea
());, but it wouldn't illustrate working with individual lines. JTextArea inputArea = new... Java: JTextArea Description A javax.swing.JTextArea is a multi-line text... use JTextField. Constructors JTextArea ta = new JTextArea(int rows
UITapgesturerecognizer not working
UITapgesturerecognizer not working  uitapgesturerecognizer not working
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java   Hi, i m interested to send the content of my jtextarea which i have developed in netbeans IDE to the webpage's textarea. how can i do
JTextArea
Java: Example - JTextArea   This is how the window looks... if there is sufficient data in the JTextArea to make them necessary.   In this example how to create object of JTextArea and add to the swing
htpasswd working
htpasswd working   hii, What does htpasswd do?   hello, htpasswd creates a new user in a specified group, and asks to specify a password for that user
How To Fetch Data From Database Into JTextArea
How To Fetch Data From Database Into JTextArea In this section we will read about how to get the data from database table into JTextArea.... To read detail about JTextArea click here. Example Here an example is being
Datagrid not working
Datagrid not working  The code here is working fine, apart from the fact that that I'm using netbeans 6.5 and the servlet v2.5 and struts 1.1.... working. please help me out
Why this is not working...?
Why this is not working...?  import java.util.*; public class Family { int size_of_family=0; public Person[] members=new Person[size_of_family]; Person d = new Person(); public Family (int size_of_family){ members = new
Update not working in hibernate.
Update not working in hibernate.  Update not working in hibernate
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
Focus method not working in firefox
Focus method not working in firefox  object.focus() is not working in firefox and chrome the element is not focused what was the problem
calender working in struts - Struts
calender working in struts  when i execute the following code ,that is working properly if i convert to struts html tags that code is not working please help me to rectify the problem
html dropdown not working firefox
html dropdown not working firefox  I am writing a Dropdown code in HTML which is not working in firefox. What could be the reason as it's perfectly working in IE and Crome. Thanks
file_exists php not working
file_exists php not working  file_exists php not working. Please give me the simple example
Dynamic-update not working in Hibernate.
Dynamic-update not working in Hibernate.  Why is dynamic update not working in hibernate?   Dynamic-update is not working. It means when you are running your update, new data is added in your table in place
UIWebView zoom not working
UIWebView zoom not working  Hi, I don't know why UIWebView zoom not working? Tell the solution. Thanks   Hi, Open the .xib file and set scalesPageToFit to YES. Thanks
Working of POS Terminal
Working of POS Terminal  Hi there, thanks for this post. Just curious how actual POS terminal will interact with PHP. PHP doesn't provide hardware interaction. Thanks for reply. Regards
StandardServiceRegistryBuilder not working in Hibernate 4.3.1
StandardServiceRegistryBuilder not working in Hibernate 4.3.1  Hi, It seems that the StandardServiceRegistryBuilder not working in Hibernate 4.3.1.... working with the Hibernate 4.3.1 and it is giving following error message: Access
background images in css not working
background images in css not working  In the application i'm passing a background image from CSS in the given format ... background-image: url("Image\backgroundImage.GIF"); which is not working. So, please give me an example
calculate working hour
calculate working hour  why echo not come out? <html><body> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> Working hour : <input name="workout" type="text"/><input name="submit1
Working with Eclipse IDE - Struts
Working with Eclipse IDE  hello, i am beginner to eclipse . i want to run my first struts program in eclipse 3.2. what are the steps for running struts in eclipse . Any body plz, tell me the setting environment of eclipse
php <? ?> tag not working
php tag not working  why PHP tags not working in my application?   This might happen when your shortopentag is turned off. So, you will have to turn it on by changing the status of this PHP tag in php.ini file. Here
command prompt is compilation is not working
command prompt is compilation is not working   Dear java users can anyone help me to run the program in command line prompt i tried by selecting the environment variable and class path and path in my system my program
window.open() not working - Ajax
is that the pop up window is not at all working.. Once I click the button, the page
Ajax not working in jsp
Ajax not working in jsp  I'm using Netbean, Ajax validation in the following code is not working the code succesfully run for first UID validation adn also for ee-mail but does not enter if else for firstname field please help me
code not working properly
code not working properly  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType
Multi Threading is not working in that why...?
Multi Threading is not working in that why...?   import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; public
working of a div tag in html
working of a div tag in html   !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
J2ME application not working on n79
J2ME application not working on n79  Hi, i had developed assignment on sun sdk and its running fine on emulator but not showing results in two text fields on my mobile phone i.e.nokia -n79.please Help public class MoneyL extends
J2ME application not working on n79
J2ME application not working on n79  Hi, i had developed assignment on sun sdk and its running fine on emulator but not showing results in two text fields on my mobile phone i.e.nokia -n79.please Help import
J2ME application not working on n79
J2ME application not working on n79  Hi, i had developed assignment on sun sdk and its running fine on emulator but not showing results in two text fields on my mobile phone i.e.nokia -n79.please Help public class MoneyL extends
J2ME application not working on n79
J2ME application not working on n79  Hi, i had developed assignment on sun sdk and its running fine on emulator but not showing results in two text fields on my mobile phone i.e.nokia -n79.please Help public class MoneyL extends
datetimepicker not working in struts2
datetimepicker not working in struts2  Hi, I am using "struts2-dojo-plugin-2.1.6.jar" and the taglib is "<%@taglib prefix="d" uri="/struts-dojo-tags"%>" **sample code:** <%@taglib prefix="s" uri="/struts-tags
Working Example for Spring AOP - Spring
Working Example for Spring AOP  Hi All, I need a complete working Java example /Code/Logic for Spring -Aspect Oriented Programming. Code provided will be highly appreciated. -- Deepak Lal
Struts application not working in LINUX - Struts
Struts application not working in LINUX  Hi ALL, I have a struts... in LINUX prodution system. The application is not recoginsed the web server is Tomcat5. I tryed with a sample servlet on linux tomcat its also not working
some methods not working on firefox and chrome
some methods not working on firefox and chrome  why some of javascript methods are not working on firefox and chrome? ex : createElement(). Please help me to solve this problem. adv thanx
Applet is not Working
Applet is not Working       This section describes you some of the trouble shooting when your applet is not working in the browser Are you running Mac OS 9? Firstly check
JOptionPane.showMessageDialog is not working on tomcat however it is working on netbeans on same machine
JOptionPane.showMessageDialog is not working on tomcat however it is working... on apacheTomcat 7.0.30 version but the same code is working on netebans 7.0, how to make it working on tomcat individually. <%@ page import
JQuery-event working new element
JQuery-event working new element  I want to know- why not an event(in JQuery) works on my created element through jQuery
Advertisements
 

 

 

DMCA.com