Home Answers Viewqa Java-Beginners Java Error In comapitable Type in statement

 
 


sushant
Java Error In comapitable Type in statement
1 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners

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 Pages:
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
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
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
error
of framework used and also the JDK version. This type error also comes when java file is complied in old version of java and used on latest version. Thanks
Java Import Statement Cleanup - Java Tutorials
Java Import Statement Cleanup 2002-06-18 The Java Specialists' Newsletter [Issue 051] - Java Import Statement Cleanup Author: Dr. Cay S. Horstmann... to receive training in Design Patterns. Java Import Statement Cleanup
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
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
type mismatch
type mismatch  Statement s= con.createStatement(); this line gives error of "type mismatch" I am using eclips nd new to servlet nd JDBC, Please help me, Thank you
Java error unreachable statement
Java error unreachable statement   ...: unreachable statement   System.out.println(i); 1 error... a code that help you in understanding a unreachable statement. For this we
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
The Switch statement
. 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.... Here is the general form of switch statement: switch (expression){ case 1
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 error illegal start of type
Java error illegal start of type       The Java error illegal start of type...;} } On Compilation the code show an illegal start of type error. Output
'if' Statement - if inside if
Java Notes'if' Statement - if inside if if inside if You can put... the condition in an if statement, Java thinks it's finished with the body... readers, is ignored by Java. This is another error that's harder to make if you
if Statement - Overview
Java Notesif Statement - Overview Purpose The purpose of the if statement is to make decisions, and execute different parts of your program depending... with if. [The other 1% of the decisions use the switch/case statement
if Statement - Overview
Java Notesif Statement - Overview Purpose The purpose of the if statement... in the scope of the if statement. This is a surprisingly common error... is a statement? A statement is a part of a Java program. We have already
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
trap error - Java Beginners
trap error  Hello. Am trying to trap this error that appears when i... type mismatch in criteria expression". what i want is a message cannot post blank..."); //Executing the sql statement to write details in the client table // String sql
incompatble type error
); } } } trows incampatble type error...incompatble type error  class ArithmeticExceptiontest { public static void main(String args[]) { int num1 = 0; int num2=10
readline Error - Java Beginners
is caused by the read() statement, just don't know why. If on step 3 you type bye...; Hi Friend, Your code works fine here. Thanks  The error
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
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
compilation error in java - Java Beginners
compilation error in java  Here is the pgm usinf if-else statement.... For removing the error you have to use the String type in place of char & your code will work without any error
'if' Statement - Braces
Java Notes'if' Statement - Braces Braces { } not required for one statement If the true or false part of and if statement has only one... was expected. What is a statement? A statement is a part of a Java
java if statement
java if statement  If statement in Java
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
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
Switch Statement example in Java
the switch statement. Here, you will learn how to use the switch statement in your java... the switch statement in Java. The following java program tells you for entering numbers... Switch Statement example in Java    
How to use switch statement in jsp code
How to use switch statement in jsp code       switch is a type of control statement used... and that will be an error. The example below demonstrates how we can use switch statement in our JSP
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
Illegal Start of Type
Illegal Start of Type  Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix...,"North"); // building interface for room type=new JLabel("Type: "); roomno=new
illegal start of type
illegal start of type  Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix... for room type=new JLabel("Type: "); roomno=new JLabel("roomNo
Java Switch Statement
Java Switch Statement       In java, switch is one of the control statement which turns the normal flow... more about the switch statement click on:   http:/www.roseindia.net/java
JSP Error - JSP-Servlet
error. HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling
Understanding jQuery statement chaining
Understanding jQuery statement chaining       Understanding jQuery statement chaining JQuery provide statement chaining which can reduce the length of the code
error in web application
error in web application  In your application when i am trying to execute it from the below page <%@ page language="java" import="java.util....++; %> <td><input type="button" name="edit" value="Edit
JSP Page Error
; <link rel="stylesheet" type="text/css" href="C:\NB\stylesheets\main.css">... style="list-style-type:none; margin:0px; padding:0px; overflow:hidden;"> <li... type="text" name="fname"> Last Name :&nbsp; <input type="text" name
JSP Page Error
; <link rel="stylesheet" type="text/css" href="C:\NB\stylesheets\main.css">... style="list-style-type:none; margin:0px; padding:0px; overflow:hidden;"> <li... type="text" name="fname"> Last Name :&nbsp; <input type="text" name
JSP Page Error
; <link rel="stylesheet" type="text/css" href="C:\NB\stylesheets\main.css">... style="list-style-type:none; margin:0px; padding:0px; overflow:hidden;"> <li... type="text" name="fname"> Last Name :&nbsp; <input type="text" name
Method is undefined for the type Object(org.apache.jasper.JasperException)
Method is undefined for the type Object(org.apache.jasper.JasperException)  [Tag:java] I am getting an Error, while accessing a JSP Page through my... on their localhost. This error is with all my JSP page where i try to access
Logic error? HELP PLEASE! :(
Logic error? HELP PLEASE! :(  Hello Guys! i have a huge problem. What...//DTD HTML 4.01 Transitional//EN"><%@page language="java" contentType="text..." /> <html> <head> <meta http-equiv="Content-Type" content
The continue statement The continue statement is used in many programming languages such as C
Continue.java Continue.java:12: unreachable statement a = i; ^ 1 error If we write...The continue statement The continue statement is used in many programming languages such as C. The continue statement The continue statement is used
error
error  The content of element type "struts" must match "(package|include|bean|constant
Error - Java Beginners
: Enter the HexaDecimal : I got error in the line String status=session.getAttribute-----> Type of error:Incompatible type found   Hi import java.io.*; import java.io.IOException.
switch statement
switch statement   i want to write a java program that computes Fibonacci,factorial,string reversal and ackerman using switch case to run as a single program
if else statement in java
if else statement in java  if else statement in java explain with example
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