Not able to insert data?

I am not able to insert the data. Am getting a compilation error . The below is my code.I have given the servername,database name,username,password in the original program.

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.*;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.io.*;

import java.lang.String;

publicclass Jinsert

{

publicstaticvoid main(String args[])throws IOException

{

Connection con =null;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

try

{

String driverName ="com.mysql.jdbc.Driver";

Class.forName(driverName);

String serverName =" ";

String mydatabase =" ";

String url ="jdbc:mysql://" + serverName +"/" + mydatabase;

String username =" ";

String password =" ";

con = DriverManager.getConnection(url, username, password);

System.out.println("Connected");

Statement stmt =null;

ResultSet rset =null;

String HolidayDate;

String Description;

stmt = con.createStatement();

System.out.println("Enter Holiday Date : ");

HolidayDate=br.readLine();

System.out.println("Enter Description : ");

Description=br.readLine();

stmt.excuteUpdate("insert into Holiday (HolidayDate, Description) values (' "+HolidayDate+" ',' "+Description+"')");

System.out.println("Data inserted");

}

catch(Exception e)

{

System.err.println("Exception: " + e.getMessage());

}

finally

{

try

{

if(con !=null)

con.close();

}

catch(SQLException e)

{

}

}

}

}

This is the error which is generated:

Jinsert.java:42: cannot find symbol

symbol : method excuteUpdate(java.lang.String)

location: interface java.sql.Statement

stmt.excuteUpdate("insert into Holiday (HolidayDate,Description) values (' "+Hol

idayDate+" ',' "+Description+"')");

^

1 error

Database is MYSQL. I have created a table called Holiday. The fields are HolidayDate which is of date datatype and Description is of varchar datatype.

what is the mistake. please help.

[3871 byte] By [venkateshpa] at [2007-9-24]
# 1
There are several things wrong with this code from my perspective, and if you want to know what, please let me know. Your mistake is that you spelled "executeUpdate" wrong you spelled it as "excuteUpdate". Verify it and try again.
WorkForFooda at 2007-7-13 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Thanks dude.. I corrected it. The program is working.can you point out the other mistakes?
venkateshpa at 2007-7-13 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Glad it's working, and sure if you are interested. I have no doubt that the best programmers would probably find much to say, but I just saw a couple of things that might help you out.

You should check the integer count returned from executeUpdate(...). It is possible that 0 rows are inserted but no Exception is thrown. It provides validation that what you are expecting to happen is really happening.

You should (in general) start variables names like HolidayDate with lower case, most people will assume an upper case variable to be a Class name. It will help you differentiate Class names and variable names too. This isn't a rule, it's just a suggestion and most code that I have seen has consistent rules for naming objects.

When doing an insert, you should almost without exception use a PreparedStatement, not a Statement. There are dozens of good reasons why, but the big one for you is that PreparedStatements will handle data conversion for you and you won't have to worry about creating a complex SQL string using concatenation and trying to figure out where the single quotes go. If you do a search in these forums on PreparedStatement you will find 100's of examples.

Just FYI. Good Luck!

WorkForFooda at 2007-7-13 > top of java,Database Connectivity,Java Database Connectivity (JDBC)...