How to verify if user already exists in MySQL database using JSP?

Hi, I am trying to create a website that allows users to register and then login. All regsitration details are stored in a MySQL table and I am attempting to have a java bean check that a new user does not already exist by looking up the username. However, I cannot get this to work, the bean is allowing anyone through. I believe there may be a problem with my while loop as the bean checks through the stored usernames in the database. Any suggestions appreciated thanks. See my code below:[
code]package foo;
import java.sql.*;
import java.util.*;
public class FormBean {
     private String firstName;
     private String lastName;
     private String email;
     private String userName;
     private String password1;
     private String password2;
     private Hashtable errors;
     public boolean validate() {
          boolean allOk=true;
          if (firstName.equals("")) {
               errors.put("firstName","Please enter your first name");
               firstName="";
               allOk=false;
          if (lastName.equals("")) {
               errors.put("lastName","Please enter your last name");
               lastName="";
               allOk=false;
          if (email.equals("") || (email.indexOf('@') == -1)) {
               errors.put("email","Please enter a valid email address");
               email="";
               allOk=false;
          if (userName.equals("")) {
               errors.put("userName","Please enter a username");
               userName="";
               allOk=false;
try {
          String database = "******hidden******";
          Class.forName("com.mysql.jdbc.Driver");
          Connection conn = DriverManager.getConnection(database,"********hidden*******");
          Statement stat = conn.createStatement();
          String query="SELECT u_name FROM users;";
          String DbUserName="";
          ResultSet rst=stat.executeQuery(query);
          while(rst.next()) {
DbUserName=rst.getString("u_name");
if (userName.equals(DbUserName)) {
allOk=false;
errors.put("userName","User name already exists, please choose another");
userName="";
conn.close();
break;
} catch (Exception ex) {
ex.printStackTrace();
          if (password1.equals("") ) {
               errors.put("password1","Please enter a valid password");
               password1="";
               allOk=false;
          if (!password1.equals("") && (password2.equals("") || !password1.equals(password2))) {
               errors.put("password2","Please confirm your password");
               password2="";
               allOk=false;
return allOk;
     public String getErrorMsg(String s) {
          String errorMsg =(String)errors.get(s.trim());
     return (errorMsg == null) ? "":errorMsg;
     public FormBean() {
     firstName="";
     lastName="";
     email="";
userName="";
     password1="";
     password2="";
     errors = new Hashtable();
     public String getFirstName() {
          return firstName;
     public String getLastName() {
          return lastName;
     public String getEmail() {
          return email;
     public String getUserName() {
          return userName;
     public String getPassword1() {
          return password1;
     public String getPassword2() {
          return password2;
     public void setFirstName(String fname) {
          firstName =fname;
     public void setLastName(String lname) {
          lastName =lname;
     public void setEmail(String eml) {
          email=eml;
     public void setUserName(String u) {
          userName=u;
     public void setPassword1(String p1) {
          password1=p1;
     public void setPassword2(String p2) {
          password2=p2;
     public void setErrors(String key, String msg) {     
          errors.put(key,msg);

Hmm, tried that and now have more build errors in the finally section.
init:
deps-jar:
Compiling 1 source file to C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\build\classes
C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\test\FormBean.java:57: cannot resolve symbol
symbol  : variable rst
location: class foo.FormBean
            if (rst != null) rst.close();
C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\test\FormBean.java:57: cannot resolve symbol
symbol  : variable rst
location: class foo.FormBean
            if (rst != null) rst.close();
C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\test\FormBean.java:58: cannot resolve symbol
symbol  : variable stat
location: class foo.FormBean
            if (stat != null) stat.close();
C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\test\FormBean.java:58: cannot resolve symbol
symbol  : variable stat
location: class foo.FormBean
            if (stat != null) stat.close();
C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\test\FormBean.java:59: cannot resolve symbol
symbol  : variable conn
location: class foo.FormBean
            if (conn != null)  conn.close();
C:\resin-2.1.11\doc\examples\basic\WEB-INF\classes\JavaLibrary1\test\FormBean.java:59: cannot resolve symbol
symbol  : variable conn
location: class foo.FormBean
            if (con != null)  conn.close();
6 errors
BUILD FAILED (total time: 1 second)Just for a quick test, I deleted the sql exception and finally code and replaced it with a regular exception just to see what happened and got no build errors, however when I run the form I am getting an sql exception from the prepared statement, parameter out of range (1 > 0). I tried reading into prepared statements, and although I now understand their basics, I still have no idea why I'm getting this error?

Similar Messages

  • How to store file content in BLOB field MySql database using java

    Hi!
    i want to store the file content in a BLOB field in MySql database using java.
    Please help me out..........
    thanx in advance...
    bye

    i stored images in db, and retrieved them. like that cant i store pdf file in db, and retrieve it back using oracle db?
    Plz help me out how to put a file in db. i need complete code. thanks in advance.

  • How to store files in mysql database using JSP?

    I'm developing an online recruitment system using JSP in server side. For the users who registers in it, I want them to upload their cv's from the web site so that I can store it in the database..I'm using mysql as the db..
    Can I know how to do it.?..or else is there any better way of doing that?
    Need a quick reply..Tx

    The best way to put data in a database in a JSP is to not do it. Instead, use a Servlet that calls a DataAccessObject. The DAO puts the data in the DB and the servlet gives the data to the DAO. The JSP does nothing but display results.
    Take a google for JSP MVC and DAO. BalusC has a great example of DAO and a JSP that uses one on his blog.

  • How to store images in BLOB field in MySql database using java

    Hi....
    Currently am able to store character string into BLOB using byte array....in MySql.
    but i cannot store images or pictures.......
    to do this.........please help me out...............
    Thanx..........:)Bye...........

    Hello,
    I have done this for Oracle but it should be similar in MySQL also. Try reading thru these links below. Mail us if you have succeeded or not.
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=654086
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=384768
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=549705
    Thanks and regards,
    Pazhanikanthan. P

  • Error when creating a user - IAM-3010183 : An error occurred while checking if a user already exists with the Common Name generated.

    Error when creating a user - IAM-3010183 : An error occurred while checking if a user already exists with the Common Name generated.

    in OIM 11g R2
    Message was edited by: 2b3c0737-074f-48d0-a760-e24e3ed9a37c

  • How do I make my already existing check boxes "checkable" [so I can check and uncheck them on PDF Expert]

    How do I make my already existing check boxes on a (PDF Document) checkable - So I can check and uncheck them on PDF Expert or Annotate 101.
    I am using ADOBE Acrobat PRO with millions of options, but no easy "here is how to do the one thing you want to do" anywhere within reason.
    Please help me.
    Thank You

    Can you check and uncheck the boxes in Acrobat?

  • How to migrate Apex users with existing passwords.

    Hi Guys,
    Our apex env finally getting a upgrade from 3.1.1 to 4.1.1 (I know, it's been overdue for years)
    Some of our apps use 'Application Express' authentication, and have few hundreds users in Apex (and users belong to diff user groups).
    The issue is, the 4.1.1 env is set up on a brand new server and DB, we want to migrate these users with their existing passwords from the 3.1.1 env.
    I tried exporting the workspace, and the users are exported as below,
         begin
         wwv_flow_fnd_user_api.create_fnd_user (
         p_user_id => '10592934818556549584',
         p_user_name => 'TEST',
         p_first_name => 'a',
         p_last_name => 'b',
         p_description => '',
         p_email_address=> '[email protected]',
         p_web_password => 'E92903DEAD135E6E86BD6B64544D2BD9',
         p_web_password_format => 'HEX_ENCODED_DIGEST_V2',
         p_group_ids => '10592435401495787816:',
         p_developer_privs=> '',
         p_default_schema=> 'TEST',
         p_account_locked=> 'N',
         p_account_expiry=> to_date('201212040000','YYYYMMDDHH24MI'),
         p_failed_access_attempts=> 0,
         p_change_password_on_first_use=> 'Y',
         p_first_password_use_occurred=> 'N',
         p_allow_access_to_schemas => '');
         end;
    when I run this in 4.1.1 I had to modify it to the new format as below,
    also changed the p_group_ids to new user group but kept the password the same
         begin
         wwv_flow_fnd_user_api.create_fnd_user (
         p_user_id => '',
         p_user_name => 'TEST',
         p_first_name => 'a',
         p_last_name => 'b',
         p_description => '',
         p_email_address=> '[email protected]',
         p_web_password => 'E92903DEAD135E6E86BD6B64544D2BD9',
         p_web_password_format => 'HEX_ENCODED_DIGEST_V2',
         p_group_ids => '1399416797653068:',
         p_developer_privs=> '',
         p_default_schema=> 'TEST',
         p_account_locked=> 'N',
         p_account_expiry=> to_date('201209041006','YYYYMMDDHH24MI'),
         p_failed_access_attempts=> 0,
         p_change_password_on_first_use=> 'Y',
         p_first_password_use_occurred=> 'N',
    p_allow_app_building_yn=> 'N',
    p_allow_sql_workshop_yn=> 'N',
    p_allow_websheet_dev_yn=> 'N',
    p_allow_team_development_yn=> 'N',     
    p_allow_access_to_schemas => '');
         end;
    the result was that the user is created fine, but the password is not valid.
    Anyone knows how to export apex users with existing password to a new server?
    Thanks.
    Edited by: Danny on 3/12/2012 20:51

    Hi,
    Not sure why you say
    when I run this in 4.1.1 I had to modify it to the new format as below, If you just run the workspace export sql it should create the Workspace, Groups and Users
    The signature of the procedure is below. See the highlighted lines.
    procedure create_fnd_user (-- Description:
    -- This procedure allows for programatic and bulk creation of users.
    -- Example:
    -- From sqlplus logged in as the privileged flows user, first
    -- ensure that the security group id is set properly, then create
    -- your users.
    <b> -- begin wwv_flow_security.g_security_group_id := 20; end;</b>
    -- begin
    -- for i in 1..10 loop
    -- wwv_flow_fnd_user_api.create_fnd_user(
    -- p_user_name => 'USER_'||i,
    -- p_email_address => 'user_'||i||'@mycompany.com',
    -- p_web_password => 'user_'||i) ;
    -- end loop;
    -- commit;
    -- end;
    -- Arguments:
    -- p_user_id numeric primary key of user
    -- p_user_name the username the user uses to login
    -- p_first_name informational only
    -- p_last_name informational only
    <b> -- p_web_password the unencrypted password for the new user</b>
    -- p_group_ids A colon delimited list of group IDs from the table wwv_flow_fnd_user_groups
    -- p_developer_privs A colon delmited list of developer privs, privs include:
    -- ADMIN:BROWSE:CREATE:DATA_LOADER:DB_MONITOR:EDIT:HELP:MONITOR:SQL:USER_MANAGER
    -- p_default_schema A valid oracle schema that is the default schema for use in browsing and
    -- creating flows
    -- p_allow_access_to_schemas A colon delimited list of oracle schemas that the user is allowed to
    -- parse as. If null the user can parse as any schema available to the company.
    -- This does not provide privilege it only resticts privilege, so listing a schema
    -- does not provide the privilege to parse as a schema, it only restricts that user
    -- to that list of schemas.
    -- p_attributes_XX These attributes allow you to store arbitary information about a given user.
    -- They are for use by flow developers who want to extend user information.
    <b> -- p_web_password_format Identifies the format of the web password.
    -- The range of values is CLEAR_TEXT, HEX_ENCODED_DIGEST, DIGEST </b>
    -- p_person_type "E" marks the user as external
    -->
    Note there is no HEX_ENCODED_DIGEST, DIGEST_V2 listed. It may work, but not obvious from the signature.
    Cheers,

  • How to verify my app store account without having to use a credit card ?

    How to verify my app store account without having to use a credit card ?

    - Whenn Yhuu First Gett A Iphonee &&'d Wanna Set Uhpp A App Storee Account Will Thee Credit Card Stuff Bhee Ohnn There ?'. &&"d Do Yhuu Havee oo2 Confirm Thee Apple Account From Yahoo .com ?'.
    Some Plz Help Lbvs I'vee Madee Likee 5 Alreadyy Ihmm Neww Do Ihtt '.

  • How To Store pdf or doc file in Oracle Database using Java Jdbc?

    can any one help me out How To Store pdf or doc file in Oracle Database using Java Jdbc in JSP/Serlet? i tried like anything. using blob also i tried. but i am able 2 store images in DB not files. please if u know or else if u have some code like this plz send that to me, and help me out plz. i need that urgent.

    Hi.. i am not getting error, But i am not getting the original contents from my file. i am getting all ASCII vales, instead of my original data. here i am including my code.
    for Adding PDF in DB i used image.jsp
    Database table structure (table name. pictures )
    Name Null? Type
    ID NOT NULL NUMBER(11)
    IMAGE BLOB
    <%@ page language="java" import="java.util.*,java.sql.*,java.io.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%
    try{
         Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.135:1521:orcl","scott","tiger");
         PreparedStatement ps,pstmt,psmnt;
         ps = con.prepareStatement("INSERT INTO pictures VALUES(?,?)");
    File file =
    new File("D:/info.pdf");
    FileInputStream fs = new FileInputStream(file);
    ps.setInt(1,4);
    ps.setBinaryStream(2,fs,fs.available());
    int i = ps.executeUpdate();
    if(i!=0){
    out.println("<h2>PDF inserted successfully");
    else{
    out.println("<h2>Problem in image insertion");
    catch(Exception e){
    out.println("<h2>Failed Due To "+e);
    %>
    O/P: PDF inserted successfully
    i tried to display that pdf using servlet. i am giving the code below.
    import java.io.IOException;
    import java.sql.*;
    import java.io.*;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class DispPDF extends HttpServlet {
         * The doGet method of the servlet. <br>
         * This method is called when a form has its tag value method equals to get.
         * @param request the request send by the client to the server
         * @param response the response send by the server to the client
         * @throws ServletException if an error occurred
         * @throws IOException if an error occurred
         public void service(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
              //response.setContentType("text/html"); i commented. coz we cant use response two times.
              //PrintWriter out = response.getWriter();
              try{
                   InputStream sPdf;
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.135:1521:orcl","scott","tiger");
                        PreparedStatement ps,pstmt,psmnt;
                   psmnt = con.prepareStatement("SELECT image FROM pictures WHERE id = ?");
                        psmnt.setString(1, "4"); // here integer number '4' is image id from the table.
                   ResultSet rs = psmnt.executeQuery();
                        if(rs.next()) {
                   byte[] bytearray = new byte[1048576];
                        //out.println(bytearray);
                        int size=0;
                        sPdf = rs.getBinaryStream(1);
                        response.reset();
                        response.setContentType("application/pdf");
                        while((size=sPdf.read(bytearray))!= -1 ){
                        //out.println(size);
                        response.getOutputStream().write(bytearray,0,size);
                   catch(Exception e){
                   System.out.println("Failed Due To "+e);
                        //out.println("<h2>Failed Due To "+e);
              //out.close();
    OP
    PDF-1.4 %âãÏÓ 2 0 obj <>stream xœ+är á26S°00SIá2PÐ5´1ôÝ BÒ¸4Ü2‹ŠKüsSŠSŠS4C²€ê P”kø$V㙂GÒU×713CkW )(Ü endstream endobj 4 0 obj <>>>/MediaBox[0 0 595 842]>> endobj 1 0 obj <> endobj 3 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj xref 0 7 0000000000 65535 f 0000000325 00000 n 0000000015 00000 n 0000000413 00000 n 0000000168 00000 n 0000000464 00000 n 0000000509 00000 n trailer <<01b2fa8b70ac262bfa939cc786f8770c>]/Root 5 0 R/Size 7/Info 6 0 R>> startxref 641 %%EOF
    plz help me out.

  • How to update transaction data automatically into MySQL database using PI

    Dear All,
    With reference to subject matter I want a sincere advice regarding how to update transaction data automatically into MySQL database using PI. Is there any link available where I can get step-by-step process.
    Ex: I have a MYSQL database in my organization. Whenever a delivery created in SAP some fields like DO Number, DO quantity, SO/STO number should get updated in MYSQL database automatically.
    This scenario is related to updation of transactional data into MYSQL DB and I want your suggestions pertaining to same issue.
    Thanks and Regards,
    Chandra Sekhar

    Hi .
    Develop a sceanrio between SAP to Database system,When the data updates in SAP Tables read the data and update it in DATA Base using JDBC adapter,but there will be some delay in updating data in MySQL.
    serach in sdn for IDOC-TOJDBC sceannario,many documents available for the same.
    Regards,
    Raja Sekhar

  • How can i upload a image file to server by using jsp or servlet.

    Hi,
    I m gurumoorthy. how can i upload a image file to server by using jsp or servlet without using third party API. pls anyone send me atleast outline of the source code.
    Pls send me anyone.
    Regards,
    Gurumoorthy.

    I'm not an applet programmer so I can't give you much advice there.
    If you want to stream the file from the server before it's entirely uploaded, then I don't believe you can treat it like a normal file. If you're just wanting to throw it up there and then listen to it, then you can treat it like a normal file.
    But again, I'm not entirely certain. You might be able to stream the start of the file from the server while you're still uploading the end of it, but it probably depends on what method you're using to do the transfer.

  • How to connect mysql database using xml

    welcome to all,
    here my doubt is how to connect mysql database using xml file, how to integrate xml file and jsp file and how to access data from dabase using jsp file. can any one help me
    regards

    Short answer: you wouldn't do any of those things. The first two are meaningless and the third is a bad practice. I have no idea what those ideas were supposed to achieve so I have no idea what tutorials I should suggest to you.

  • How to connect MySql database with JSP

    Dear everyone,
    how to connect MySql database with JSP......

    It's too bad that nobody has ever asked this question before...

  • How to connect oracle form6i or 10g to mysql database

    can anyone tell me how to connect oracle forms to mysql database using ODBC connector?
    akin

    Hi
    this is step by step installation guide
    http://download.oracle.com/docs/cd/E11882_01/install.112/e10875/toc.htm
    also below link for download
    http://www.oracle.com/technology/software/products/database/index.html
    hope this helps
    Zekeriya

  • Hi can anyone explain me how to  syncronize two database using jsp?

    Hi can anyone explain me how to syncronize two database using jsp?

    I thinking than you really need the jsp page for calling the java methods whith sincronize the database.You think wrong.
    You wrote a bad question.What was bad about it?
    You need a java method for sincronize the two databases using a jsp page.No you don't, see my answer.

Maybe you are looking for

  • Is $99 sign up required before you can test code on a device (iphone/itouch

    Hi Is the $99 sign up required before you can test code on an iPhone/ Itouch device? I am just trying to compile a simple program and run it on the device, but I get a CodeSign error. Is Codesign something that can be done without signing up for $99,

  • Xcode 3.1.2 and applescript studio...

    Hi everyone! I have been previously unable to upgrade to Xcode 3.1 because when I open my script there is so much empty spacing now inserted between lines and characters and I'm not sure if it's going to be a problem or not. I just tried to upgrade t

  • Purchae order

    Hi...can anyone define the correct meaning of vendor..can a customer also be a vendor.. I am in trasaction me2n for purchase orders. now in that purchase order my material number and the vendor material number is different..whyy is that..that is the

  • Question from today's event on adobe connect

    HI I was bumped off todays event by my own mistake and did not get to hear the answers to my questions. If someone can answer them here, it would be great! The speaker advised to use Q&A vs chat if you have a large audience. Please define in numbers

  • Simplest way to transfer Contacts/Addresses to the Curve using iMac / Palm Desktop ?

    I have a new 8300 Curve and approximately 1500 Contacts/Addresses in my iMac on Palm Desktop ( they are also in Palm handheld). I am able to export these Contacts/Addresses to my iMac desktop in various formats: excel workbook, .csv Comma Delimited ,