Inserting a value to an Enum field in Table

Inserting a value to an Enum field in Table

I'm writing a code that creates a user account and sends the result to the user table in a mysql database.

For example, in the user table I have:

username varchar(15) PRIMARY KEY,
password varchar (10),
is_Admin enum('Y','N'),

In the Java code I have a user class with similair attributes:

private String username;
private String password;
private boolean isAdmin;

With all the normal accessors, mutators, etc.

My create an account function is like this:

User user = new User ();

out.print("\nUsername: ");
user.setUsername( input.nextLine() );

out.print("\nPassword: ");
user.setPassword( input.nextLine() );
input.nextLine();


out.print("\n(1) Admin or (2) Limited user: ");
    if ( input.nextInt() == 1 )
           user.setIsAdmin( true );
    else
           user.setIsAdmin ( false );

String query = "INSERT INTO user VALUES ('" + user.getUsername() + "', '" + user.getPassword() + "', " + user.getIsAdmin() + ")";

Needless to say this didn't work so I even changed isAdmin to an int and set either a 1 if the user wanted the new account to be an admin and 0 if it's a restricted user. I thought since in the database it would read the 1 as a 'Y' and 0 as a 'N' but I get some database error that says data truncated. How do I set this enum field in the table?

View Answers

August 17, 2011 at 10:29 PM

Nvm (not that anyone did), I fixed it.









Related Tutorials/Questions & Answers:
Inserting a value to an Enum field in Table
Inserting a value to an Enum field in Table  I'm writing a code that creates a user account and sends the result to the user table in a mysql... this enum field in the table
Inserting Image into table
Inserting Image into table  In this section , we will insert a image into a table. For inserting image, table's field (in which image will be stored) must be define as "blob". First, Create table'inImage'
Advertisements
How to add radio button value in a table for particular field?
How to add radio button value in a table for particular field?  Hi,I have a jsp form in which one static field for date and below a dynamic table... one radio button for text field then it insert only one value absent OR present
How to get enum value in Java
How to get enum value in Java  Hi all, i am looking for a solution to get an enum value from index in Java. Please suggest. Thanks
inserting value - JSP-Servlet
inserting value  sir i want to create a web application when we use the jsp inserting the value in the jsp after that i want these value inserted the database mySQl with the help of servlet. Inserting form data   
ModuleNotFoundError: No module named 'drf-enum-field'
ModuleNotFoundError: No module named 'drf-enum-field'  Hi, My... named 'drf-enum-field' How to remove the ModuleNotFoundError: No module named 'drf-enum-field' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'drf-enum-field'
ModuleNotFoundError: No module named 'drf-enum-field'  Hi, My... named 'drf-enum-field' How to remove the ModuleNotFoundError: No module named 'drf-enum-field' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-enum-field'
ModuleNotFoundError: No module named 'django-enum-field'  Hi, My... named 'django-enum-field' How to remove the ModuleNotFoundError: No module named 'django-enum-field' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'drf-enum-field'
ModuleNotFoundError: No module named 'drf-enum-field'  Hi, My... named 'drf-enum-field' How to remove the ModuleNotFoundError: No module named 'drf-enum-field' error? Thanks   Hi, In your python
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
inserting all the values in a html table column
inserting all the values in a html table column  strong text hai everyone, i'm a fresher to servlet i need to know that, how can i insert all the values in a html table column into a database. Thanks in advance
problem on jsp, inserting data into table(mysql).
problem on jsp, inserting data into table(mysql).  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html... selected india and then goa. I want to insert it to a table which has two fields
enum
enum  HOW TO INSERT enum constants at runtime into the enum
retrieve record from the field table
,kanchipuram for a single record. I have to retrieve these data from the field table...retrieve record from the field table  Hi. I have a field in database... values like chennai as one value, trichy as one value. and i have to show it in html
enum
enum  why we are not created child for enum type? why we are not extending any from enum
how to insert value in dynamic table
a dynamic table for every company.but whenever i'm inserting values to the company... student table. and company and year value i'm getting through company table.but apache...how to insert value in dynamic table  i am creating a project
enum
enum  enum concept is developed based on class concept,but we can extend any class from our class,but why it is not passiable to extend by enum? every class in java directly and indirectly child class of Object class,every enum
File Upload in struts2 - Invalid field value for field
File Upload in struts2 - Invalid field value for field   Hi I am... : Invalid field value for field "upload". My webContents->Web-Inf->lib... value for field "upload". on jsp page but not in console Please guide I am stuck
I have to retrieve these data from the field table
the field table. Actually they are separated by comma. I want to take the values...I have to retrieve these data from the field table  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values
Inserting Image in Database Table
Inserting Image in Database Table   ... (Image table). For inserting an image in table, we have used the SQL statement... to the MySQL database table.  Flow of the process : ADS_TO_REPLACE_1
Records are not inserting in to main table while running the mysql stored procedure.
Records are not inserting in to main table while running the mysql stored... that procedure records are not inserted into main table from temp table.But im getting msg... me with this issue. My Code: BEGIN select concat('Inserting into SD
Retrieve Value from Table - Hibernate
Retrieve Value from Table   Hai friend, I need help, How can i retrieve values From database using hibernate in web Application. As I new to hibernate I couldn't find solution for this problem.. Can anyone help please.. 
Update only specific field value in elasticsearch
Update only specific field value in elasticsearch  Hi, I am using... into the existing document. How to Update only specific field value... only specific field value in elasticsearch by the following query
Inserting values in MySQL database table
Inserting values in MySQL database table   ... the facility for inserting the values in MySQL database table. Description... affected" but if any problems comes while inserting the data  in the table
Retrieving value from multiple table in database
Retrieving value from multiple table in database  Hi fnds, I want to maintain the financial database of 20 users for 1 year and update the details... created 12 tables with table name - month1,month2,....,upto month12.. each table
how to get the value of a label field of option tag in javascript?
how to get the value of a label field of option tag in javascript?  example <select> <option label="2" value="A">A</option> <option label="5" value="B">B</option> <
Can not input value into text field which use sx:datetimepicker
Can not input value into text field which use sx:datetimepicker  I am... value from calendar, it runs normal. But i input value from keyboard by hands and then i move focus to other element, that value is lost. Thus, i can not input
Can not input value into text field which use sx:datetimepicker
Can not input value into text field which use sx:datetimepicker  I am..." cssStyle="font-size:13.5px" accesskey="true" />"); I input value from calendar, it runs normal. But i input value from keyboard by hands and then i move focus
JComboBox Insert Edited Value Into Table
JComboBox Insert Edited Value Into Table In this section we will read about... in to insert an editable value of JComboBox into a table. We will use an Java editor... through command prompt. To insert a value into the table we will use MS-Access
link in the field of table on clicking he link the full data will displayed
link in the field of table on clicking he link the full data will displayed... having a college database, in it I am having a student table in which there are id... and displaying it in a jsp page. I want set up a hyperlink in the name field so
How to collect Java input field value display into Jtable?
How to collect Java input field value display into Jtable?  <p>We would like to know how to collection input field data into Jtable with the following format. Please advise.</p> <ol> <li>text field
how to display data from database according to entered value in search field
;/html> i suppose to get this table, but it shows wrong value .i want...how to display data from database according to entered value in search...;form method="post" name="form1" action="viewsearch.jsp"> <table border="1
Inserting Data In Database table using Statement
Inserting Data In Database table using Statement... for inserting the values into the table. This query we will write inside the executeUpdate... to insert the data in the database from our java program in the table stored
php inserting date into mysql
php inserting date into mysql  php inserting date into mysql  ..., data is a database table. <?php table $query_manual = "INSERT INTO data... = "INSERT INTO data(dp_name, dp_date) VALUE ('DATE: Auto CURDATE()', CURDATE
use data from database table as hyperlink value - JSP-Servlet
use data from database table as hyperlink value  I'm creating a web... to hyperlink. I want to use this data as hyperlink and use it as the value... as the hyperlink's value then pass to the next page and retrieve the complete details of the row
need ENUM examples
need ENUM examples  i need enum sample examples
enum php mysql
enum php mysql  How to use mysql enum in php
I need jsp code for how to write text field value into property file.
I need jsp code for how to write text field value into property file.  Hi , I need to set the text field value into property file using jsp code. Example : Username : Valar , I have entered the value "Valar" in the text field
my table should be reseted to new value upon the selection of the combo box..
my table should be reseted to new value upon the selection of the combo box... class purchase extends javax.swing.JFrame { JTable table; DefaultTableModel model...); } catch(Exception e) { e.printStackTrace(); } //table creation
Hibernate hello world
In this section, you will learn about basic tutorial of inserting value in the database table and printing "hello world" on the console after successful insertion
use struts 1.0 to view sql table value on JSP page
use struts 1.0 to view sql table value on JSP page  Here i am using struts 1.0 to view my sql table values on jsp page. But the problem is when i append the value in bean then i find the last row of table is shown repetedly. Any
use struts 1.0 to view sql table value on JSP page
use struts 1.0 to view sql table value on JSP page  Here i am using struts 1.0 to view my sql table values on jsp page. But the problem is when i append the value in bean then i find the last row of table is shown repetedly. Any
how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server?
how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server?  how to convert the entire column field which is in encryted like 1263332444 of table to dd/mm/yyyy format in microsoft sql server? i
ModuleNotFoundError: No module named 'enum'
ModuleNotFoundError: No module named 'enum'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'enum' How to remove the ModuleNotFoundError: No module named 'enum' error
ModuleNotFoundError: No module named 'enum'
ModuleNotFoundError: No module named 'enum'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'enum' How to remove the ModuleNotFoundError: No module named 'enum' error
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.  i have MYSQL DB,DB NAME:TRLIST, TABLE NAME:TR_LIST; (FIELD NAMES:NODE,PACKAGE,TR), {VALUES:Row1(CCN,CS4.0,XXX),Row2(SDP,CS5.0,YYY
SQL Alter Column Default Value
, This field would take default value of '10'. ALTER TABLE... with Create Table Statement. The default value will be set as per specified... to table. The Describe table show you the Table attribute like field, data
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks

Ads