Share on Google+Share on Google+

Dani B
Inserting a value to an Enum field in Table
1 Answer(s)      5 years and 8 months ago
Posted in : JDBC

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?

Ads

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
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
Advertisements
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'
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
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   
enum
enum  HOW TO INSERT enum constants at runtime into the enum
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
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
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
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
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
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
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
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
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
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
Inserting Image in Database Table
Inserting Image in Database Table   ...). For inserting an image in table, we have used the SQL statement ?INSERT... to the MySQL database table.  Flow of the process : This program
Inserting values in MySQL database table
Inserting values in MySQL database table   ... the facility for inserting the values in MySQL database table. Description...; but if any problems comes while inserting the data  in the table
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.. 
enum php mysql
enum php mysql  How to use mysql enum in php
need ENUM examples
need ENUM examples  i need enum sample examples
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
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
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit Here Thanks
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit Here Thanks
about enum - Java Beginners
about enum  hi all, please tell me about "enum" and explain with example. And its use in OOP. Thanks
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads