syntax error in SQL Insert Statement

syntax error in SQL Insert Statement

private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent ae){
//tab1
if(ae.getSource()==bt1ok){
// String date=tf1dob.getText();
// if(isValidDate(date))
// {

int prnnumber=Integer.parseInt(tf1id.getText());
String dateadmi=tf1date.getText();
String lastname=tf1ln.getText();
String firstname=tf1fn.getText();
String midname=tf1mn.getText();
String dateofbirth=tf1dob.getText();
String addressvalue=tf1address.getText();
String cityvalue=tf1city.getText();
String eduvalue=tf1edu.getText();
String percentage=tf1per.getText();
String genderdetail=text.getText();
String contactnum=tf1cont.getText();
int entmarks=Integer.parseInt(tf1ent.getText());
String coursename= jccourse.getSelectedItem().toString();
int coursefees=Integer.parseInt(tf1cfees.getText());
String coursetype=tf1ctype.getText();
//String academicyear= jcayear.getSelectedItem().toString();
// int academicyear=jcayear.getSelectedIndex()+1;
// int coursename = jccourse.getSelectedIndex()+1;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1 =DriverManager.getConnection("jdbc:odbc:mydsn","","");
Statement stmt=con1.createStatement();
int i=stmt.executeUpdate("insert into newfresher(prn,date,lname,mname,dob,address,city,edu,per, gender,contact,ent,cname,cfees,ctype) values(" + prnnumber + ",'"+dateadmi+"', '"+lastname + "', '" +firstname + "','"+midname+"','"+dateofbirth+"','"+addressvalue+"','"+cityvalue+"','"+eduvalue +"','"+percentage+"','"+genderdetail+"','"+contactnum+"','"+entmarks+"','"+coursename+"',"+coursefees+",'"+coursetype+"')");//,'"+academicyear+"'
/*PreparedStatement stm=con1.prepareStatement("Insert into newfresher(prn,date,lname,fname,mname,dob,address,city,edu,per, gender,contact,ent,cname,cfees,ctype,ayear) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");//'" +dateadmi+ "',
stm.setInt(1, prnnumber);
stm.setString(2,dateadmi);
stm.setString(3,lastname);
stm.setString(4,firstname);
stm.setString(5,midname);
stm.setString(6,dateofbirth);
stm.setString(7,addressvalue);
stm.setString(8,cityvalue);
stm.setString(9,eduvalue);
stm.setString(10,percentage);
stm.setString(11, genderdetail);
stm.setString(12,contactnum);
stm.setInt(13,entmarks);

stm.setString(14, coursename);
stm.setInt(15,coursefees);
stm.setString(16,coursetype);
stm.setString(17, academicyear);
// stm.setInt(16, academicyear);




stm.executeUpdate();*/
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
con1.close();
}//end try
catch(Exception e){
System.out.println(e);
}//end catch*/
//JOptionPane.showMessageDialog(null,"Valid Date","STUDENT INFORMATION SYSTEM",JOptionPane.INFORMATION_MESSAGE);
//}//end if
// else
// {
// JOptionPane.showMessageDialog(null,"Invalid Date.","STUDENT INFORMATION SYSTEM",JOptionPane.INFORMATION_MESSAGE);
// }


}//end source if
}//end action performed
}//end listeners
View Answers

April 10, 2010 at 2:43 PM

Hi Friend,

Your field name 'date' in the database table 'newfresher' contradicts. Therefore change your field name 'date' to 'day' and run the following query:

int i=stmt.executeUpdate("insert into newfresher(prn,day,lname,fname,mname,dob,address,city,edu,per, gender,contact,ent,cname,cfees,ctype) values("+prnnumber+",'"+dateadmi+"','"+lastname+"', '"+firstname + "','"+midname+"','"+dateofbirth+"','"+addressvalue+"','"+cityvalue+"','"+eduvalue +"','"+percentage+"','"+genderdetail+"','"+contactnum+"','"+entmarks+"','"+coursename+"',"+coursefees+",'"+coursetype+"')");//,'"+academicyear+"'


Thanks









Related Tutorials/Questions & Answers:
syntax error in SQL Insert Statement - Java Beginners
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... Access Driver] Syntax error in INSERT INTO statement. plz Help Me  Hi
syntax error in SQL Insert Statement - Java Beginners
syntax error in SQL Insert Statement   private class ButtonListener...","",""); Statement stmt=con1.createStatement(); int i=stmt.executeUpdate("insert into newfresher(prn,date,lname,mname,dob,address,city
Advertisements
sql syntax error help
sql syntax error help  this query show syntax error .. i am unable to figure it out insert into order (orderdate, dpname, paymethod, tamount...') where is the error ?   Please send the error details and the datatype
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
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
The INSERT INTO Statement, SQL Tutorial
the following SQL statement: INSERT INTO employee (emp_name...The INSERT INTO Statement       The INSERT INTO statement is used to insert or add a record
PHP SQL Insert Statement
PHP SQL Insert Statement       PHP SQL Insert Statement show you the message when the records..._TO_REPLACE_1 The Tutorial illustrate an example from 'PHP SQL Insert Statement
to write an SQL query using insert statement
to write an SQL query using insert statement  I need to write an sql query for the below using InSERT command.pls help. Insert 5-star ratings by James Cameron for all movies in the database. Leave the review date as NULL
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... = ?"; PreparedStatement pst = connection.prepareStatement(sql); pst.setString
JDBC Batch Example With SQL Insert Statement
JDBC Batch Example With SQL Insert Statement: In this tutorial, we are discuss about insert SQL statement with the jdbc batch. First of all, we... SQL insert statement for save data in the datasource and add
The INSERT INTO Statements in SQL?
The INSERT INTO Statements in SQL?  The INSERT INTO Statements in SQL?   Hi, The INSERT INTO statement is used to insert a new row or multiple rows into a table.ADS_TO_REPLACE_1 SQL INSERT INTO Syntax INSERT
SQL And Statement
SQL AND Statement      ... 11 SQL AND Operator Syntax The SQL AND Operator... on condition. The Syntax used for SQL AND Operator is given as : 
The INSERT INTO Statement
The INSERT INTO Statement       The INSERT INTO statement is used to insert or add a record...' with there specific values then we should use the following SQL statement:ADS
What is the syntax for a CREATE TABLE statement?
What is the syntax for a CREATE TABLE statement?  What is the syntax for a CREATE TABLE statement
ERROR 601 (42P00): Syntax error. Encountered
ERROR 601 (42P00): Syntax error. Encountered   Hi, In HBase program I am executing the insert into query, but it is giving following error: ERROR 601 (42P00): Syntax error. Encountered "insert" at line 1, column 1. How
SQL SELECT DISTINCT Statement
'. SQL statement to insert data into table: insert into Stu_Table... SQL SELECT DISTINCT Statement     ... with the select statement. The SQL Distinct clause is used with the Select statement
insert into statement in sql using servlets
insert into statement in sql using servlets   ... insert a value from a html form in the table stored in the database. ... we are going to insert the values. Now make one jsp page or  html page
Jdbc Insert Statement
JDBC Insert Statement       Add a row to a existing table using insert statement in JDBC. The tutorial illustrates an example from JDBC Insert Statement. In this program
JDBC Prepared Statement Insert
JDBC Prepared Statement Insert   ... Statement Insert. In this Tutorial  the code describe the include a class... the value of record set. The select sql statement is used to retrieve
SQL statement - SQL
SQL statement  Hi, i have an sql statement that needs to add the price, vat and shipping cost. It works fine but one problem is that the shipping... be charged 10. otherwise nothing. Heres the code: $orderAmount = 0; $sql
The Update Statement in SQL.
The Update Statement in SQL.  The Update Statement in SQL.   Hi, here is the answer,ADS_TO_REPLACE_1 The update statement in the sql is written as follows- UPDATE table_name SET column_name = new_value WHERE column
Syntax error in my UPDATE..please advise
Syntax error in my UPDATE..please advise  Hi experts, I tested my... in your SQL syntax; check the manual that corresponds to your MySQL server version...) And here's my UPDATE Statement: String sql = "UPDATE members SET strNRICNO
Insert Operation Error - WebSevices
Insert Operation Error  Hai, How i store my full resume in database[Mysql] using PHP. Any one Know the code..... Help me
SQL Error - SQL
SQL Error  Invalid character value for cast specification on column number 5 (Designation) Whats this error about this if the field i specified in programming error. ie DB fields in above question
error
error  I am running a program insert into statement in sql using.../ServletUserEnquiryForm.shtml getting an error given below SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error please suggest
Select Statement in SQL, SQL Tutorial
The SELECT statement for SQL       SELECT key word is used to select data from a table. ADS_TO_REPLACE_1 Syntax:    ADS_TO_REPLACE_2      ADS
SQL Avg Syntax
SQL Avg Syntax       SQL Avg Syntax is used to compute the average of the records in a table. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example from 'SQL
SQL Backup query with where statement
SQL Backup query with where statement       SQL Backup query with where statement ... Insert into statement add the records or rows to the table 'Stu_Table
How to Solve the Syntax Error in java??
How to Solve the Syntax Error in java??  Syntax error in java? i have tried this program its showing error like this in Eclipse "Syntax error... of the program "objectname.i" What is the reason for this error??How to access the variable
SQL QUERY ERROR
SQL QUERY ERROR  Im writing a query which shows error of INVALID CHARACTER The Query is Insert into PMST_EMP_MST(PMSNUM_EMP_ID,PMSSTR_EMP... IN THE DATABASE. PLEASE HELP ME.  Syntax of insert query is: INSERT
ModuleNotFoundError: No module named 'sql-insert-writer'
named 'sql-insert-writer' error? Thanks   Hi, In your...: No module named 'sql-insert-writer' error will be solved. Thanks...ModuleNotFoundError: No module named 'sql-insert-writer'  Hi, My
Need SQL Statement
IS THE SQL STATEMENT NEEDED TO ACHIEVE THESE RESULTS...Need SQL Statement  QUESTION IS CAPITALIZED AT THE BOTTOM... There is a table Employee, with three columns: Name (varchar), Department (varchar
SQL Error Version 5.5.15
SQL Error Version 5.5.15  SQL Error Version 5.5.15
Insert Date using Statement - Development process
Insert Date using Statement   Hi, plz send me code for Storing system date using statement instead of preparedstatement. Thanks Prakash  Hi Friend, Try the following code: Thanks
The UPDATE Statement, SQL Tutorial
should use the following SQL statement : ADS_TO_REPLACE_3 Syntax... a specified criteria. In the given syntax of update statement the keyword SET... The UPDATE Statement      
Create After Insert Trigger in SQL
Create After Insert Trigger in SQL   ... illustrate a example from 'Create After Insert Trigger in SQL'. In this Example, we create a table 'Stu_Table' and 'Stu_Log' using create table statement
mysql select statement - SQL
statement code. Implement the following code. import java.sql.*; public class...); Statement st = con.createStatement(); ResultSet rs
JDBC Insert Statement Example
.style1 { text-align: center; } JDBC Insert Statement Example JDBC Insert statement allow you to insert record into the table of the database... the database and insert record to the database. At first create table named student
SQL AND Statement
SQL AND Statement      ... 11 SQL AND Operator Syntax The SQL AND Operator... on condition. The Syntax used for SQL AND Operator is given as : 
SQL Bulk Insert Example
SQL Bulk Insert Example       SQL Bulk Insert Example is used to insert a bulk record... illustrate an Example to create SQL Bulk Insert .To grasp this example we create
SQL Bulk Insert Example
SQL Bulk Insert Example       SQL Bulk Insert Example is used to insert a bulk record to the table... to create SQL Bulk Insert .To grasp this example we create a table 'Stu
correct the sql error
correct the sql error  i am getting a SQL Error while retriving data...(null,"Please enter the Student ID to Search","Error",0); } else { try...:odbc:college"); Statement st=con.createStatement
JSP SQL Error
JSP SQL Error  Hi While trying to execute the below code i'm getting the following error "java.sql.SQLException: Io exception: Got minus one from...:oracle:thin:@localhost:8084:dsn","system","tiger"); Statement st=null
SQL SELECT DISTINCT Statement
'.ADS_TO_REPLACE_3 SQL statement to insert data into table... SQL SELECT DISTINCT Statement   ... clause with the select statement. The SQL Distinct clause is used with the Select
SQL error - JSP-Servlet
SQL error  Hello friends, Can we update a column...(url+dbname,userName,password); try{ Statement st...){ System.out.println("Error occured while updating!!!"); } con.close
help with JDateChooser to insert date into sql
Statement stmt=con.createStatement(); stmt.executeUpdate("insert into special...help with JDateChooser to insert date into sql  TextField3 = new com.toedter.calendar.JDateChooser(); TextField3.setDateFormatString("MM-d-yâ
SQL STATEMENT in JDBC in NETBEANS IDE
SQL STATEMENT in JDBC in NETBEANS IDE  Iam using NETBEANS IDE. Iam developing a bank application. Using JDBC in SERVLETS For the withdraw function, "bal" and "ano" are user inputs when i wrote like, st.executeQuery("UPDATE
PHP SQL Insert
PHP SQL Insert       PHP SQL Insert is used to insert the record from HTML page to Mysql ... illustrate an example from PHP SQL Insert . To understand the example, firstly
The DELETE Statement, SQL Tutorial
The DELETE Statement       The DELETE statement is used to delete rows from a table. database will update that is why deletion and insertion of data will be done.  Syntax  ADS
SQL select statement doesn't return any rows,
SQL select statement doesn't return any rows,  When an SQL select statement doesn't return any rows, is an SQLException thrown

Ads