Java Error In comapitable Type in statement

Java Error In comapitable Type in statement

Here I want to Check wheter entered id is already Exists in Database or Not
with Access Database,
Plz Help Me Sir
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class faculty3
{
JFrame j;
JPanel j1,j2,j3;
JTabbedPane tp;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12;
JButton addbtn,editbtn,resbtn,delbtn,savebtn; //Buttons
Connection con;
PreparedStatement st;
//Statement st;
faculty3() //constructor
{
j=new JFrame("faculty");
j1=new JPanel(new GridLayout(6,3));
j2=new JPanel(new GridLayout(5,2));
j3=new JPanel(new GridLayout(3,2));
tp=new JTabbedPane();
l1=new JLabel(" id");
l2=new JLabel("name");
l3=new JLabel("qualification");
l4=new JLabel("department"); //for panel j1
l5=new JLabel("id");
l6=new JLabel("name");
l7=new JLabel("qualification");
l8=new JLabel("department"); //for panel j2
l9=new JLabel("Enter the id"); //for panel j3
t1=new JTextField(20);
t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
t4=new JTextField(20);
t5=new JTextField(20);
t6=new JTextField(20);
t7=new JTextField(20);
t8=new JTextField(20);
t9=new JTextField(20);
addbtn=new JButton("Add");
resbtn=new JButton ("Reset");
editbtn=new JButton("Edit");
savebtn=new JButton("Save");
delbtn=new JButton("Delete");
j1.add(l1);
j1.add(t1);
j1.add(l2);
j1.add(t2);
j1.add(l3);
j1.add(t3);
j1.add(l4);
j1.add(t4);
j1.add(addbtn);
j1.add(resbtn); //complete the j1 panel
j2.add(l5);
j2.add(t5);
j2.add(l6);
j2.add(t6);
j2.add(l7);
j2.add(t7);
j2.add(l8);
j2.add(t8);
j2.add(editbtn); //for Edit purpose
j2.add(savebtn); //for save the edit effect
j3.add(l9);
j3.add(t9);
j3.add(delbtn); //for j3 pan
//complete the reset action

addbtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
//String v1=t1.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:mydsn","","");
try
{
PreparedStatement st = con.createStatement();

int ide;//=Integer.parseInt(v1);
ResultSet rs=st.executeQuery("select id from faculty where id like '"+'%'+ide+'%'+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"Already Exists");
}
}//end try
catch(Exception e)
{
JOptionPane.showMessageDialog(j1,"Error in submitting data!");
}//end catch
}// end Action Performed
});//end Action Listener
}
void dis()
{
j.getContentPane().add(tp);
tp.addTab("Additional record",j1);
tp.addTab("Edit the record",j2);
tp.addTab("Deletion the Record",j3);
j.setSize(400,380);
j.setVisible(true);
j.setResizable(true);
}//end display method
public static void main(String args[])
{
faculty3 f=new faculty3();
f.dis();
}// end main method
}//end Class
View Answers

March 20, 2010 at 11:05 AM

Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class faculty3{
JFrame j;
JPanel j1,j2,j3;
JTabbedPane tp;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12;
JButton addbtn,editbtn,resbtn,delbtn,savebtn; //Buttons
Connection con;
PreparedStatement st;
//Statement st;
faculty3(){
j=new JFrame("faculty");
j1=new JPanel(new GridLayout(6,3));
j2=new JPanel(new GridLayout(5,2));
j3=new JPanel(new GridLayout(3,2));
tp=new JTabbedPane();
l1=new JLabel(" id");
l2=new JLabel("name");
l3=new JLabel("qualification");
l4=new JLabel("department"); //for panel j1
l5=new JLabel("id");
l6=new JLabel("name");
l7=new JLabel("qualification");
l8=new JLabel("department"); //for panel j2
l9=new JLabel("Enter the id"); //for panel j3
t1=new JTextField(20);
t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
t4=new JTextField(20);
t5=new JTextField(20);
t6=new JTextField(20);
t7=new JTextField(20);
t8=new JTextField(20);
t9=new JTextField(20);
addbtn=new JButton("Add");
resbtn=new JButton ("Reset");
editbtn=new JButton("Edit");
savebtn=new JButton("Save");
delbtn=new JButton("Delete");
j1.add(l1);
j1.add(t1);
j1.add(l2);
j1.add(t2);
j1.add(l3);
j1.add(t3);
j1.add(l4);
j1.add(t4);
j1.add(addbtn);
j1.add(resbtn);
j2.add(l5);
j2.add(t5);
j2.add(l6);
j2.add(t6);
j2.add(l7);
j2.add(t7);
j2.add(l8);
j2.add(t8);
j2.add(editbtn); //for Edit purpose
j2.add(savebtn); //for save the edit effect
j3.add(l9);
j3.add(t9);
j3.add(delbtn); //for j3 pan
//complete the reset action
addbtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String v1=t1.getText();
String v2=t2.getText();
String v3=t3.getText();
String v4=t4.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
Statement st = con.createStatement();
int ide=Integer.parseInt(v1);
ResultSet rs=st.executeQuery("select id from faculty where id like '"+'%'+ide+'%'+"'");
if(rs.next()){
JOptionPane.showMessageDialog(null,"Already Exists");
}
else{
int i=st.executeUpdate("insert into faculty(id,name,qualification,department) values('"+v1+"','"+v2+"','"+v3+"','"+v4+"')");
JOptionPane.showMessageDialog(null,"Inserted Successfully");
}
}//end try
catch(Exception e){
JOptionPane.showMessageDialog(j1,"Error in submitting data!");
}//end catch
}// end Action Performed
});//end Action Listener
}
void dis(){
j.getContentPane().add(tp);
tp.addTab("Additional record",j1);
tp.addTab("Edit the record",j2);
tp.addTab("Deletion the Record",j3);
j.setSize(400,380);
j.setVisible(true);
j.setResizable(true);
}//end display method
public static void main(String args[]){
faculty3 f=new faculty3();
f.dis();
}// end main method
}//end Class

Thanks









Related Tutorials/Questions & Answers:
Java Error In comapitable Type in statement - Java Beginners
Java Error In comapitable Type in statement  Here I want to Check...; //Statement st; faculty3() //constructor { j=new JFrame("faculty"); j1...(j1,"Error in submitting data!"); }//end catch }// end Action
Java error missing return statement
Java error missing return statement       Java error missing return statement are those error in Java that occurred when a programmer forget to write
Advertisements
Array list in Java - arraylist type error
Array list in Java - arraylist type error  I am using Array list in Java but when i compile i get array list type error. Can anyone please explain what is array list type error and why it occurs
syntax error in SQL Insert Statement - Java Beginners
Access Driver] Syntax error in INSERT INTO statement. plz Help Me  Hi...syntax error in SQL Insert Statement  Dear Sir ,I have write following code to save data into access databse, but code gives following error code
syntax error in SQL Insert Statement - Java Beginners
syntax error in SQL Insert Statement   private class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent ae...","",""); Statement stmt=con1.createStatement(); int i
Java error unreachable statement
Java error unreachable statement   ... a code that help you in understanding a unreachable statement. For this we have a class name' unreachable error', Inside the main method  we have
error : not an sql expression statement
error : not an sql expression statement  hii I am gettin followin error in connecting to database SQLserver 2005 in Jdeveloper,i m usin struts... { Connection conn = DatabaseManager.getConnection(); Statement stmt
Java error illegal start of type
Java error illegal start of type       The Java error illegal start of type... start of type error. Output Compiling 1 
incompatble type error
); } } } trows incampatble type error...incompatble type error  class ArithmeticExceptiontest { public static void main(String args[]) { int num1 = 0; int num2=10
oracle insert statement error - JDBC
oracle insert statement error  hi.. please help me to insert a image into oracle 11g database and please say me how can i insert image from directory like G:\imagefolder\ultrasoundimage\02us02.jpeg please help me
java if statement
java if statement  If statement in Java
data type used to store name.(getting an error)
data type used to store name.(getting an error)    Statement stm=con.createStatement(); String query="select * from employee where ename... getting an error like dis: "ename cannot be resolved to a variable" whats
For Loop Statement in java 7
For Loop Statement in java 7 In this section, we will discuss about for loop in java 7. This is one type of  loop statement. For Loop Statements : For loop is one way of looping to iterate block of code under certain condition
if else statement in java
if else statement in java  if else statement in java explain with example
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
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
GOTO Statement in java
GOTO Statement in java  I have tried many time to use java goto statement but it never works i search from youtube google but e the example on net are also give compile error. if possible please give me some code with example
Java callable statement
Java callable statement  What is callable statement? Tell me the way to get the callable statement
JAVA statement - Java Beginners
JAVA statement  The import statement is always the first noncomment statement in a Java program file.Is it true?  Hi Friend, No,it is not true.If your class belongs to a package, the package statement should
java code for print true if even and false if odd and print error if any float value with out using conditional and looping statement
java code for print true if even and false if odd and print error if any float value with out using conditional and looping statement  hi class...%2!=0); System.out.println(error
conditional statement in java
conditional statement in java  Write a conditional statement in Java   Logical and comparison statements in OOPs are also know as conditional statements. You can learn "How to write conditional statement in Java " from
Java error
Java error  class WhileLoopMethod{ public static void main(String... = 88; while(a } //it is giving compile time error .....illegal start of type
Java error
Java error  class WhileLoopMethod{ public static void main(String... = 88; while(a } //it is giving compile time error .....illegal start of type
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.  String sql = "UPDATE emp_details SET empEname = ?, emailId = ?, guid =?, proximityCard =?, managerEmailId = ?, reviewerEmailId
Java error identifier excepted
Java error identifier excepted       Java Error Identifier excepted occurred... that help you in understanding the Java error identifier excepted. For this we
Java type casting
Java type casting  What is Downcasting
eraser type generics in java
eraser type generics in java  Explain eraser type generics in java with example
Java type casting
Java type casting  Can a Byte object be cast to a double value
If statement in java 7
If statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. There are various way to use if statement with else - If Statement :ADS_TO_REPLACE_1  If statement
Java IF statement problem
Java IF statement problem  Dear Sir/Madam i am using the following code. expected to not have any output but it still showing "welcome".. please help me why it showing "welcome". class c1 { int a=5; while(a>1
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
methods type - Java Beginners
methods type in Java  Give me an example programs of methods types in Java
Reference type Vs Object type. - Java Beginners
Reference type Vs Object type.  Can anyone explain the exact.... They never contain the object. C++ object variables may be either, but Java supports only object references. For Example : Book bookvar = new Book("Java
Switch Statement in java 7
Switch Statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. Switch Statements : The switch statement is used when you want to test many statements based on some
Java error incompatible types
operator = is used to show you an incompatible type error in java rather than... Java error incompatible types       Java Error incompatible types occurred when
Type casting in java
Type casting in java In this section you will learn about type casting in java. Type casting is to convert one type to another type. Java support two types... a double type cast to int type    Reference type casting : In java type
Branching Statements in java 7
Branching Statements in java 7 In this section, we will discuss about Branching Statements in java 7. This is one type of control flow statement. Branching... statement is another branching statement provided by the java 7. Its
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
java- jdbc with type 4 driver
java- jdbc with type 4 driver  My program code is----- import java.sql.*; import java.lang.* ; import java .io.*; import java.util.*; import... = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:XE", "system", "oracle"); Statement
different type input in java
different type input in java  hiiiii... get input different different type like as DataInputStream,Scanner i want to get source code of these all type of input method. thank   Java Read through DataInputStream: import
type casting - Java Beginners
type casting and conversion  I am beginner and my query is Importance of type casting and conversion  Hi friend,public class TypeCasting...://www.roseindia.net/java
Switch Statement example in Java
for understanding more about the switch statement in Java. The following java...;SwitchExample" and two integer type values from users. Java I/O Package has a input Stream... Switch Statement example in Java    
Java - Continue statement in Java
Java - Continue statement in Java       Continue: The continue statement is used in many programming languages such as C, C++, java etc. Sometimes we do not need to execute some
Java Type Casting - Java Beginners
Java Type Casting  what is object type casting? give some example with related
Getting A File's Mime Type In Java
Getting A File's Mime Type In Java  Getting A File's Mime Type In Java
Break Statement in java 7
Break Statement in java 7 In this tutorial we will discuss about break statement in java 7. Break Statement : Java facilitate you to break the flow... : If you want to terminate the outer statement java provides the way to do
Type Conversion - Java Beginners
Type Conversion   Hai, rajanikanth, Please explain how to convert from integer value to a string value .In a database operation i want to convert it.   hi jagadish Suppose int num = 10; String id = ""+num
Java Switch Statement
Java Switch Statement       In java, switch is one of the control statement which turns the normal flow... an error. To know more about the switch statement click on:   http
Continue Statement in java 7
Continue Statement in java 7 In this tutorial we will discuss about continue statement in java 7. Continue Statement : Sometimes you need to skip block... statement in loops.ADS_TO_REPLACE_1 In java 7, Continue statement stops the current

Ads