Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to fix this?

  1. #1
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to fix this?

    I get an error: Unknown column 'a' in 'field list'. The values i have entered are: edit_name=a, edit_ip=b, edit_os=c, edit_ram=123, old_name=1(I have 4 records with that name). Here is my code, how to fix this issue?
    public static void EditInformation(String old_name, String edit_name, String edit_IP, String edit_OS, int edit_RAM, Connection conn, String url, String dbName, String driver, String userName, String password){		
    			try {
    				Class.forName(driver).newInstance();
    				conn=DriverManager.getConnection(url+dbName, userName, password);
    				try {
    					Statement st = conn.createStatement();
    					int val=st.executeUpdate("UPDATE server "+
    							"SET name="+edit_name+",ip="+edit_IP+",os="+edit_OS+",ram="+edit_RAM+" "+
    							"WHERE name="+old_name);
    				}
    				catch(SQLException s){
    			        System.out.println("SQL statement is not executed!");
    				}
    			}
    			catch (Exception e){
    				e.printStackTrace();
    				}
    		}


  2. #2
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: How to fix this?

    Quote Originally Posted by noFear View Post
    I get an error: Unknown column 'a' in 'field list'. The values i have entered are: edit_name=a, edit_ip=b, edit_os=c, edit_ram=123, old_name=1(I have 4 records with that name). Here is my code, how to fix this issue?
    assuming that the edit_name column in the database table is defined as a char, then your assignment should be

    edit_name='a'

    and so on.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to fix this?

    Try surrounding your entries with quotes:

    int val=st.executeUpdate("UPDATE server "+
    							"SET name=\""+edit_name+"\",ip=\""+edit_IP+"\",os=\""+edit_OS+"\",ram=\""+edit_RAM+"\" "+
    							"WHERE name=\""+old_name + "\"");