Results 1 to 3 of 3
  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    187
    Rep Power
    2

    Default Insert Enum in Database

    Assume the following enumeration:
    Java Code:
    public enum FederalState {BW, BY, BE, BB, BR, HH, HE, MV, NI, NR, RP, SL, SN, ST, SH, TH}
    Java Code:
    public class Location {
    	
    	private FederalState state;
    	private String ort;
    	private String PLZ;
    	private String strasse;
    	private String country;
    
    //setters and getters
    
    PreparedStatement ps = null;
    ps = con.prepareStatement(query);
    
    	           Iterator<Location> it = set.iterator();
    	           while (it.hasNext()){
    	           Location obj = it.next();
    
    	           ps.setString(1, obj.getState()); //error State is type enum not String but there is no setEnum
    	           ps.setString(2, obj.getOrt());	           
    	           ps.setString(3, obj.getPLZ());
    	           ps.setString(4, obj.getStrasse());
    
    	       	     ps.executeUpdate();
    because state is enumeration type (not String or another type) so how to deal with it to get the write instruction with prepareStatement

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Insert Enum in Database

    Cross posted at setter of Type Enum

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Insert Enum in Database

    toString() the enum value?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Create registration form | insert into database | call the database
    By FamilyGuy in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-23-2012, 11:08 AM
  2. insert vector to database
    By jperson in forum JDBC
    Replies: 4
    Last Post: 01-20-2011, 02:42 AM
  3. how to insert data in database
    By Vinay Bhatia in forum JDBC
    Replies: 6
    Last Post: 11-03-2010, 04:06 PM
  4. why i can't insert data to database
    By khaa_khay in forum Web Frameworks
    Replies: 0
    Last Post: 05-26-2010, 05:37 AM
  5. Replies: 3
    Last Post: 02-28-2009, 09:17 AM

Posting Permissions

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