Results 1 to 2 of 2
  1. #1
    jacksons5 is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Post getting error while inserting a row in table thru program

    Hi All,

    I am having a tablespace named Incident which has eight columns . The first column is index which i kept as auto increment. The columns are

    1.index(auto_increment)
    2.ticket_no (String)
    3.date(String)
    4.description (String)
    5.priority (int)
    6.state (String)
    7.follow_up (String)
    8.status (String)

    Now i tried to insert test row in my database, i am getting the error as below

    "Unknown column 's1' in 'field list'" . My code and detailed error message is below. Please check it.

    Java Code:
    public void actionPerformed(ActionEvent e) {
    	// TODO Auto-generated method stub
    	
    	String s1,s2,s3,s4,s5,s6,s7;
    	int i;
    	
    	if(e.getActionCommand().equals("incident")){
    	
    	
    		s1= "test";
    		s2= "test";
    		s3 = "test";
    		i=2;
    		s5= "test";
    		s6 = "test";
    		s7= "test";
    		
    		try {
    			statement.executeUpdate("INSERT INTO incident" + "(ticket_no, date, description, priority,state,follow_up,status)" + "values" + "(s1,s2,s3,i,s5,s6,s7)");
    		} catch (SQLException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		}
    		
    		
    		
    	}
    	
    }
    	
    	
    }

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Unknown column 's1' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:41 1)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:4187)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:4119)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:25 70)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :2731)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2809)
    at com.mysql.jdbc.StatementImpl.executeUpdate(Stateme ntImpl.java:1811)
    at com.mysql.jdbc.StatementImpl.executeUpdate(Stateme ntImpl.java:1725)
    at MainWindow.actionPerformed(MainWindow.java:466)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: getting error while inserting a row in table thru program

    Please use code tags next time

    Your quotation marks in executeUpdate are wrong, it`s all a string, you dont use the variables s1-s7 + i!

    Java Code:
    statement.executeUpdate("INSERT INTO incident (ticket_no, date, description, priority,state,follow_up,status) values" + "("+s1+","+s2+","+s3+","+i+","+s5+","+s6+","+s7+")");

Similar Threads

  1. Replies: 1
    Last Post: 04-23-2013, 01:50 PM
  2. problem with inserting into table
    By pardhu in forum AWT / Swing
    Replies: 2
    Last Post: 11-19-2011, 05:46 AM
  3. Help on inserting into table
    By ShinTec in forum JDBC
    Replies: 4
    Last Post: 06-08-2010, 10:26 AM
  4. Inserting a Table in a TextFile?
    By Keerti in forum Advanced Java
    Replies: 5
    Last Post: 11-19-2008, 05:31 PM
  5. Inserting into a table (Example)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 10:25 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •