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 2 of 2

Thread: setter of Type Enum

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    46
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default setter of Type Enum

    Assume the following enumeration:
    public enum FederalState {BW, BY, BE, BB, BR, HH, HE, MV, NI, NR, RP, SL, SN, ST, SH, TH}

    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
    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: setter of Type Enum

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/80758-insert-enum-database.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. Enum with strings
    By popnfresh in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2013, 08:12 PM
  2. enum
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 23rd, 2012, 03:19 PM
  3. Needing some help with array getter and setter methods!!
    By BlackShadow in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 5th, 2012, 07:11 PM
  4. [SOLVED] Project help...confusion with changing a getter/setter for a driver class
    By coolidge in forum Java Theory & Questions
    Replies: 1
    Last Post: September 30th, 2011, 11:08 PM
  5. How to convert from type double to type int?
    By rph in forum Object Oriented Programming
    Replies: 7
    Last Post: July 25th, 2011, 04:21 AM