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 TableInserting 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 get enum value in JavaHow 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-Servletinserting 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
inserting all the values in a html table columninserting 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
enumenum 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
enumenum 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
enumenum
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
Retrieve Value from Table - HibernateRetrieve
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 elasticsearchUpdate 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 databaseRetrieving
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 JComboBox Insert Edited Value Into TableJComboBox 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
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 mysqlphp
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-Servletuse 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
Hibernate hello worldIn 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 pageuse 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 pageuse 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
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 examplesneed
ENUM examples i need
enum sample examples
Hi Friend,
Visit HereADS_TO_REPLACE_1
Thanks
need ENUM examplesneed
ENUM examples i need
enum sample examples
Hi Friend,
Visit HereADS_TO_REPLACE_1
Thanks