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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sushant
Java Error In comapitable Type in statement
1 Answer(s)      4 years and 6 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

Advertisement
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 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
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
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
incompatble type error
); } } } trows incampatble type error...incompatble type error  class ArithmeticExceptiontest { public static void main(String args[]) { int num1 = 0; int num2=10
java if statement
java if statement  If statement in Java
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
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
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
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  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
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
Java callable statement
Java callable statement  What is callable statement? Tell me the way to get the callable statement
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 switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch 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
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
Java type casting
Java type casting  What is Downcasting
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
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
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
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 :  If statement contains one boolean
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
Java error
Java error  class WhileLoopMethod{ public static void main(String... = 88; while(a } //it is giving compile time error .....illegal start of type
 

 

 

DMCA.com