doubt

doubt

View Answers

September 19, 2008 at 6:06 PM

Hi friend,


import java.awt.Font;
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.*;
import java.applet.*;
import java.sql.*;
import java.net.*;
import java.io.*;

public class DataInsertApplet extends Applet implements ActionListener {

JLabel text, clicked;
JButton button, clickButton;
JTextField textField;
private boolean clickMeMode = true;
private Connection c;
private String driver = "com.mysql.jdbc.Driver";
private String user = "amar";
private String pass = "amar123";
private String url = "jdbc:mysql://192.168.10.211:3306/";;
private String db = "amar";

public void init(){
text = new JLabel("Text to save to file:");
clicked = new JLabel("Text retrieved from file:");
button = new JButton("Click Me");
button.addActionListener(this);
clickButton = new JButton("Click Again");
clickButton.addActionListener(this);
textField = new JTextField(20);
setLayout(new BorderLayout());
setBackground(Color.white);
add(BorderLayout.NORTH, text);
add(BorderLayout.CENTER, textField);
add(BorderLayout.SOUTH, button);
}

public void start(){
}

public void stop(){
System.out.println("Applet stopping.");
}

public void destroy(){
System.out.println("Destroy method called.");
}

public void actionPerformed(ActionEvent event){
try{
Class.forName (driver);
c = DriverManager.getConnection(url+db,user,pass);
}catch (Exception e){
e.printStackTrace();
System.exit(1);
}

Object source = event.getSource();
if(source == button){
if(clickMeMode){
JTextArea displayText = new JTextArea();
try{

//Write to database
String theText = textField.getText();
Statement stmt = c.createStatement();
String updateString = "INSERT INTO employeedetail VALUES ('"+theText+"')";
int count = stmt.executeUpdate(updateString);

//Read from database

ResultSet results = stmt.executeQuery("SELECT empname FROM employeedetail ");
while(results.next()){
String s = results.getString("empname");
displayText.append(s + "\n");
}
stmt.close();
}catch(java.sql.SQLException e){
System.out.println("Cannot create SQL statement");
System.exit(1);
}

//Display text read from database
text.setText("Text retrieved from file:");
button.setText("Click Again");
clickMeMode = false;

//Display text read from database

} else {
text.setText("Text to save to file:");
textField.setText("");
button.setText("Click Me");
clickMeMode = true;
}
}
}
}


September 19, 2008 at 6:09 PM

<HTML>
<BODY>

<APPLET CODE=DataInsertApplet.class WIDTH="300" HEIGHT="200">
</APPLET>

</BODY>
</HTML>

-------------------------

Visit for more information.

http://www.roseindia.net/java/example/java/applet

Thanks.









Related Tutorials/Questions & Answers:
doubt this
doubt this  what is the use of "this" and "super" keyword
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Advertisements
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt
doubt
doubt
Doubt
DOUBT
doubt
doubt
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
doubt in struts - Struts
doubt in struts   i don't understand the concept on Resource bundle in struts can u please help me out
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
doubt regarding JSF
doubt regarding JSF  Hi, pls explain what is difference between struts &JSF? pls explain what is difference between SPRING &JSF
"Doubt on Swing" - Java Beginners
"Doubt on Swing"  Hi Friend.... Thanks for ur goog Response.. i need to create a GUI Like... pic1.gif RadioButton pic2.gif RadioButton Pic3.gif RadioButton If we have select d appropriate radio
Doubt Regarding Charts
Doubt Regarding Charts  Hi, Can you please help me out by answering "hoe to include charts in core java code and struts code" thanks in advance, Swaroop Eswara   Please visit the following link: Jfreechart
Version of com.martiansoftware>hope-and-doubt dependency
List of Version of com.martiansoftware>hope-and-doubt dependency
Doubt in struts - Struts
Doubt in struts  I am new to Struts, Can anybody say how to retrieve data from database and display it in jsp. Some said to use beans but i dont know how to do. Please help me in this regard. It will be helpful, if explained
Doubt on Segmentation - Java Beginners
Doubt on Segmentation  Hi .. ImageProcessing.. How to segment the each and every characters from the bitmap image Consider for an example bitmap1.bmp: Visuallc++ text is on bitmap1.bmp..How to extract those from image
Doubt regarding charts and jsp
Doubt regarding charts and jsp  Hi, I successfully executed the bar chart in normal java application. But I want the Bar Chart to be executed in web application(jsp). So,please help me out in how to connect the normal
Doubt regarding charts and jsp
Doubt regarding charts and jsp  Hi in the http://www.roseindia.net/chartgraphs/barchart-jsppage.shtml of the code (new StandardEntityCollection()); final File file1 = new File("../webapps/jspchart/web/barchart.png
DOubt in Mysql connections
DOubt in Mysql connections  i have some problem regarding data base connections, i have created a hostname, username and password in filezilla server but after i give those names also it is showing error like this: mysql
Doubt In Sql query
Doubt In Sql query  Hi Have a glance @ http://img98.imageshack.us/img98/4348/tableo.png For a single country there may be n numbers of country_notes. I Need to fetch all the distinct records of countries with the latest country
doubt about JMS selector
doubt about JMS selector  Hi! , i have a little problem with message selector in JMS api. I'am try develop a request and response with JMS queue, but I didnÃ?´t get success. in my case, i send a message to server, server
doubt about JMS selector
doubt about JMS selector  Hi! , i have a little problem with message selector in JMS api. I'am try develop a request and response with JMS queue, but I didnÃ?´t get success. I use this reference site like guide. in my
Doubt about Xstream Converter
Doubt about Xstream Converter  Hi, I am using the Xstream freamwork to read a lot of files in a batch operation. I use a custom converter Xstream to read some properties of my Xml file, but when I changed my application
doubt on synchronized block in java
doubt on synchronized block in java  Hi ! some people are feeling bore on my regular questions on threads. Do not feel bore on my regular questions.I.... I think you got my doubt. I request you to clarify my doubt based on below
doubt in combobox in flex - XML
doubt in combobox in flex  hi, i have doudt in combobox in flex which is a combination of mxml and actioscript . In my project i has a combobox with 10 items when i select the particular item i has 2 display
Doubt in servlets - JSP-Servlet
Doubt in servlets  Good Evening sir/madam, I want to add data dynamically for that which methods i have to use to retrieve the dynamic data .  Hi Friend, Try the following code: 1
doubt in ejb3 - EJB
doubt in ejb3  hi i am new to ejb3 .i have written simple code which look like these entitybean package EntityBean; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Table; @Entity
doubt - Date Calendar
doubt about retrieve dates from Database  Retrieve dates from the database with some condition in dates in JSP   i want to retrieve datas from the database with some condition in dates in jsp   Retrieve data
doubt in inheritance program - Java Beginners
doubt in inheritance program  how will we get the result 6 2 5 in the inheritance program in the given example i got 6 &2 but i am confused about 5
I have doubt in jsp file.
I have doubt in jsp file.  I have doubt in jsp file. In a jsp file, there should be two buttons. One is start and other is stop. When we click on start then only stop should be enabled. Other wise it should be disabled. When
servlet doubt on online examination system
servlet doubt on online examination system  hai. sir ,i am doing project in online examination system. taken back end as mysql database. and doing the programs using java servlet. MY PROBLEM and doubt is 1. how 2 skip
Hi Friend.. Doubt on + - Java Beginners
Hi Friend.. Doubt on +   Hi friend... import java.io.*; class Plus { public static void main(String args[]) { int a=10; int b= 25; System.out.println("A = " + a + " B = " + b
Doubt on Data Types - Java Beginners
Doubt on Data Types  Hi Friend doubt on DataTypes... How should i declare n Assign value to the Float variable; Can u Please COMPILE this Program...Explain in detail
Hi Friend.. Doubt on + - Java Beginners
Hi Friend.. Doubt on +   Hi friend... import java.io.*; class Plus { public static void main(String args[]) { int a=10; int b= 25; System.out.println("A = " + a + " B = " + b
Hi ..doubt on DATE - Java Beginners
Hi ..doubt on DATE  Hi Friend...Thank u for ur valuable response.. IS IT POSSIBLE FOR US? I need to display the total Number od days by Each month... WAIT I WILL SHOW THE OUTPUT: --------------------------------- ENTER
doubt in connecting to mysql in flex - XML
doubt in connecting to mysql in flex  The ?Create application from database? is a Flex 3 feature that enable you to create simple applications in few... all!! i have doubt 2 set path of webroot n root URL and after valid
doubt in connecting mysql in flex - XML
doubt in connecting mysql in flex  The ?Create application from database? is a Flex 3 feature that enable you to create simple applications in few...!! i have doubt 2 set path of webroot n root URL and after valid coniguration pls
Maven Dependency hope-and-doubt >> 0.1.0
You should include the dependency code given in this page to add Maven Dependency of com.martiansoftware >> hope-and-doubt version0.1.0 in your project
Hi...doubt on Packages - Java Beginners
Hi...doubt on Packages  Does import.javax.mail.* is already Existing Package in java.. I have downloaded one program on Password Authentication .. i Have seen javax.mail.*; ---> What does it mean.. can any one pls

Ads