Inserting a value to an Enum field in Table

Ads
 

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.

Ads









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
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
Advertisements
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
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
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 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
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
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
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
enum
enum  HOW TO INSERT enum constants at runtime into the enum
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
enum
enum  why we are not created child for enum type? why we are not extending any from enum
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
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
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
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
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
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
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
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
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
SQL Alter Column Default Value
with Create Table Statement. The default value will be set as per specified.... The Describe table show you the Table attribute like field, data type etc. Create...)) and set the default value for this field is set '10'.Whenever you leave

Ads