www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > Other

    Other Discussion and technical support for any other scripting methods.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 04-30-2004, 12:14 AM
    jilshi jilshi is offline
    Registered User
     
    Join Date: Feb 2004
    Posts: 47
    Unhappy insert data into database

    i am using jsp to create web site. How can i insert data into database but do not have text box in the web site. i want to have data automatically show in the database without having people key in data from web site. the purpose for doing this is i want to generate default answer for every member.
    Reply With Quote
      #2  
    Old 04-30-2004, 01:04 AM
    buntine buntine is offline
    Super Moderator
     
    Join Date: Jan 2004
    Location: Melbourne, Australia
    Posts: 5,527
    You will need to use an SQL query like the following.
    Code:
    INSERT INTO tableName (fieldOne) VALUES ('valueOne');
    Here is a good article i found: http://www.roseindia.net/mysql/mysql.htm

    Regards,
    Andrew Buntine.
    __________________
    http://www.andrewbuntine.com
    Reply With Quote
      #3  
    Old 04-30-2004, 02:29 AM
    jilshi jilshi is offline
    Registered User
     
    Join Date: Feb 2004
    Posts: 47
    Unhappy

    i want to generate answer for the user. every user will have different answer. their answer will be what is their lot no. i already generate question for them which is "what is my lot no?"
    i attach part of my code. Every data in the code are fine except "answer" part because data that insert into database was wrong. data in database under "answer" field all has same data.


    <% if (session.getAttribute("user_name") != null) {

    String uName = (String)session.getValue("user_name");
    String sql_1 = "SELECT es_iden, es_access_no "+
    "FROM esaccs "+
    "WHERE es_usr_id='"+uName+"' ";
    Statement stmt_1 = conn.createStatement();
    ResultSet rset_1 = stmt_1.executeQuery(sql_1);
    while (rset_1.next()) {
    ident = rset_1.getString("es_iden");
    accNo = rset_1.getString("es_access_no");
    //answer = rset_1.getString("es_ans");
    }

    String sql_2 = "SELECT fs_email_addr "+
    "FROM fcrsdt "+
    "WHERE fs_access_no = '"+accNo+"' ";
    Statement stmt_2 = conn.createStatement();
    ResultSet rset_2 = stmt_2.executeQuery(sql_2);
    while (rset_2.next()) {
    emailAddr = rset_2.getString("fs_email_addr");
    out.print(emailAddr);
    //lotno = rset_2.getString("fs_lot_no");
    //out.print(lotno);
    }
    String select_e = "SELECT fs_lot_no "+
    "FROM fcrsdt "+
    "WHERE fs_lot_no = '"+answer+"' ";
    Statement stmt_e = conn.createStatement();
    ResultSet rset_e = stmt_e.executeQuery(select_e);
    if (rset_e.next()) {
    answer = rset_e.getString("fs_lot_no");
    out.print(answer);
    session.setAttribute("answer", answer);
    }
    }

    try {
    int totalRecordInDatabase = 0;
    int intAccsNo = 1;
    String sql = "SELECT count(*) as recordCount "+
    "FROM fcrsdt "+
    "WHERE fs_cat_typ ='O' ";
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(sql);
    if (rset.next()) {
    totalRecordInDatabase = rset.getInt("recordCount");
    }
    int iZero, iNine, iA, iZ, randNum;
    StringBuffer bufUserID;
    StringBuffer bufPassword;
    //StringBuffer bufQuestion;
    StringBuffer bufAnswer;

    String strAccessNo="",accessNo,userID,password, question;

    iZero = '0';
    iNine = '9';
    iA = 'A';
    iZ = 'Z';

    Random randGen = new Random(System.currentTimeMillis());
    bufUserID = new StringBuffer();
    bufPassword = new StringBuffer();
    //bufQuestion = new StringBuffer();
    //bufAnswer = new StringBuffer();

    while (intAccsNo <= totalRecordInDatabase) {
    strAccessNo = String.valueOf(intAccsNo);
    accessNo = strAccessNo+".00";

    for (int i = 0; i< 6; i++) {
    randNum = randGen.nextInt(iZ);
    while (!(randNum >= iZero && randNum <= iNine) &&!(randNum >= iA && randNum <= iZ)) {
    randNum = randGen.nextInt(iZ);
    }
    char c = (char)randNum ;
    bufUserID.append(c);
    }//for
    for (int ii= 0; ii< 6; ii++) {
    randNum = randGen.nextInt(iZ);
    while (!(randNum >= iZero && randNum <= iNine) &&!(randNum >= iA && randNum <= iZ)){
    randNum = randGen.nextInt(iZ);
    }
    char c = (char)randNum ;
    bufPassword.append(c);
    }//for

    userID = bufUserID.toString();
    password = bufPassword.toString();
    question = "What is my lot no?";
    answer = answer;
    out.print(answer);

    bufUserID.delete(0,7);
    bufPassword.delete(0,7);
    //bufQuestion.delete(0,7);
    //bufAnswer.delete(0,7);
    String sql_insert ="INSERT INTO esaccs(es_access_no,es_usr_id,es_password,es_sts,e
    s_iden,es_question,es_ans) "+
    "VALUES(?,?,?,?,?,?,?)";
    PreparedStatement ps_1 = conn.prepareStatement(sql_insert);
    ps_1.setString(1,accessNo);
    ps_1.setString(2,userID);
    ps_1.setString(3,password);
    ps_1.setString(4,"A");
    ps_1.setString(5,"O");
    ps_1.setString(6,question);
    ps_1.setString(7,answer);
    ps_1.executeUpdate();
    ps_1.close();
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:47 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.