If and else statement



Share on Google+Share on Google+

Christopher De Souza
If and else statement
2 Answer(s)      7 years ago
Posted in : JDBC
View Answers

September 6, 2009 at 11:53 AM

Additional details:

The word is referring to the word column.

September 7, 2009 at 10:43 AM

Hi Friend,

Try the following code:

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

public class SearchWord extends JFrame{
JTextField text1,text2;
JLabel label1,label2;
JButton button;
static JPanel panel;
JTextArea area;
JScrollPane pane;
public SearchWord(){
text1=new JTextField(10);
label1=new JLabel("Enter word");
text2=new JTextField(10);
label2=new JLabel("Enter Description");
button=new JButton("Submit");
panel=new JPanel(new GridLayout(3,2));
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String word = text1.getText();
String description = text2.getText();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from search where word='"+word+"'");
String w="";

JOptionPane.showMessageDialog(null, "Word already exist.");

int i=st.executeUpdate("insert into search(word,description) values('"+word+"','"+description+"')");
JOptionPane.showMessageDialog(null, "Word is successfully added");

catch(Exception ex){}
public static void main(String[]args){
SearchWord search=new SearchWord();



Related Tutorials/Questions & Answers:
if else statement in java
if else statement in java  if else statement in java explain with example
if else statement in java
if else statement in java  explain about simple if else statement and complex if else statement in java with an example
ELSE STATEMENT!! - Java Beginners
ELSE STATEMENT!!  Hi! I just want to know why doesn't my else statement works? Else statement is there in the code below which is: else JOptionPane.showMessageDialog(null, n+ " is not in the array!");//doesn't work
If and else statement - JDBC
If and else statement  Dear Sir, I had created a statement...); ======================================================= how to create a if and else statement...: ====================================================== Connection c = null; Statement stmt2 = null; try{ //Load the driver
IF-Else Conditional Statement
IF-Else Conditional Statement Conditional Statements are used to carry out actions based on condition. If-Else is also a conditional statement used... the following conditional statement : if statement if...else statement
IF - PHP If and else Statement
IF - PHP If and else Statement in PHP “IF” is a conditional... uses if else statement as a conditional operator. Lets take an example... want. Syntax of PHP if else if Statement if (condition)   Execute
Java if else
Java if else       The if-else statement is one of the widely used control flow statements while... to the programmer to handle the condition based programming. Syntax for if-else
The else Keyword
The else Keyword        The else is the one more keyword of Java. It is used to specify a statement..., the code after the else keyword is executed. It is an optional part of a branching
If and else if ladder
If and else if ladder  How we can use if and else if statement?  ...) System.out.println("Grater than 100"); else if(i < 50) System.out.println("Grater than 50"); else
if/else statements
if/else statements  I'm having a hard time programming this question: code an if/else statement that test the value of a string variable named.... If the value is "UPS," code another if/else statement that tests the value
If-else not working
If-else not working  <%@ page contentType="text/html; charset..."); Statement stmt=conn.createStatement(); ResultSet rs=null...="SELECT REGNO,SNAME FROM sub_comb WHERE L_category='Lab'"; } else if (Lab
If-else not working
If-else not working  <%@ page contentType="text/html; charset..."); Statement stmt=conn.createStatement(); ResultSet rs=null...="SELECT REGNO,SNAME FROM sub_comb WHERE L_category='Lab'"; } else if (Lab
for statement
for statement  for(int i=0;i<5;i++); { system.out.println("The value of i is :"+i); } if i end for statement what will be the output   got the answer.. it displays only the last iteration that is "The value of i
programes on if....else
or not write a program to find minimum of 3 nos using nested if else. write... a program to input score of a student out of 100 and print grades using else...){ System.out.println("Leap Year!"); } else{ System.out.println("Not a Leap
if else in javascript function
if else in javascript function  How can i write the else statement in JavaScript to check if the web browser is IE or not? Is there any other way to validate this way ..? Thanks
if else condition - Java Beginners
if else condition  Please explain the if else condition in Java programming language
Objective C if else statements syntax
Objective C if else statements syntax  What is the syntax of if else statements in Objective C?   Using of if else statement in Objective C There is no changes in the syntax format of if else statement. You can write
. In JSTL if-else tag is not implemented directly like the if-else statement... as an if-else statement in JSTL programming. Sample code given below expresses you how... to use the if-else conditional statement in JSTL. In this example we will create
switch case instead of if else
switch case instead of if else  How to write code in switch case instead of if else in Java
Java if else condition
Java if else condition  its there any similar condition for (X<=5 || y<=10) please post the answer as soon as possible.... TQ
PHP Else Construct
does not met, it means that we place the else construct after if statement and if  'if statement' does not met, then the else part... else part only when if statement is false, it is also true that we can not use
check condition in if-else block
check condition in if-else block  Hi, I want to update database with following query int i= st.executeUpdate("Insert into text_editor(words) values('"+words+"')"); how can I give a check option so only valid words are inserted
using if and else if statments
using if and else if statments  Hello everyone Hope all are well Just new here & already have a question. I have a little veg shop it sells 6... if and nested if and else if This has my head in bits for days I have the below done x6
Control Tags-If / Else If / Else
Control Tags-If / Else If / Else      ... are used for flow control such as if, else and iterate.)  'If' tag could be used by itself or with 'Else If' Tag and/or single/multiple 'Else' Tag. Create
jstl if else
In this section we have discussed about how to implement if-else tag in JSTL..., as their is not default value. Hence, if-else tag is not implemented directly but is implemented with the help of some tags: <c:choose> tag : works like if-else
Operators; If, Else, Elseif; Loops
be true as it sets $ Studentname to Ajay. 3.9.2. if...else statement.... If..else statement execute the code in both conditions, e.g. It works like... statement ‘He is not Ajay'. 3.9.3. if...elseif....else statement
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2 multiply and i keep getting this error illegal start of expression else... + number2)); else if (selection = - 'S') System.out.println(number1
Statement block
Statement block  What is the purpose of a statement block
PHP Conditional Statement
supports if , else, switch case and conditional operator for this purpose. PHP Conditional Statement Example 1: <?php $a=12; if($a>10)  ...;$b)     echo "\$a is greater than \$b"; else
The Switch statement
it becomes cumbersome to write lengthy programs using if and if-else statements. To avoid this we can use Switch statements in Java. The switch statement is used... of a variable or expression. The switch statement in Java is the best way to test
Use if statement with LOOP statement
Use if statement with LOOP statement   ... with Example The Tutorial illustrate a example from if statement with LOOP statement. In this example we create a procedure display that accept
Java Spring Hibernate Struts Training java.lang.classnotfoundexception com.mysql.jdbc.driver how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu


Advertisement null