Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:35:30+00:00 2026-06-08T09:35:30+00:00

I have this Java method which I will use to insert data from JSF

  • 0

I have this Java method which I will use to insert data from JSF form into Oracle:

public int saveData(int result) throws SQLException, java.text.ParseException, NoSuchAlgorithmException {

        String SqlStatement = null;

        if (ds == null) {
            throw new SQLException();
        }

        Connection conn = ds.getConnection();
        if (conn == null) {
            throw new SQLException();
        }

        PreparedStatement ps = null;

        /*

        CREATE TABLE USERS(
            USERID INTEGER NOT NULL,
            GROUPID INTEGER,
            SPECIALNUMBER VARCHAR2(60 ),
            USERNAME VARCHAR2(50 ),
            PASSWD VARCHAR2(50 ),
            DATETOCHANGEPASSWD DATE,
            ADDRESS VARCHAR2(60 ),
            STATEREGION VARCHAR2(50 ),
            COUNTRY VARCHAR2(50 ),
            USERSTATUS VARCHAR2(30 ),
            TELEPHONE VARCHAR2(50 ),
            DATEUSERADDED DATE,
            USEREXPIREDATE DATE,
            DATEUSERLOCKED CHAR(20 ),
            CITY VARCHAR2(50 ),
            EMAIL VARCHAR2(50 ),
            DESCRIPTION CLOB
        )
        /
        */

        try {
            conn.setAutoCommit(false);
            boolean committed = false;
            try {           /* insert into Oracle the default system(Linux) time */
        InsertSqlStatement = "INSERT INTO USERS"
                        + " (USERID, GROUPID, SPECIALNUMBER, USERNAME, PASSWD, DATETOCHANGEPASSWD,"
                        + " ADDRESS, STATEREGION, COUNTRY, USERSTATUS, TELEPHONE, DATEUSERADDED," 
                        + " USEREXPIREDATE, DATEUSERLOCKED, CITY, EMAIL, DESCRIPTION)"
                        + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        UpdateSqlStatement = "UPDATE USERS "
                                + "SET "
                                    + "USERID = ?, "
                                    + "GROUPID = ?, "
                                    + "SPECIALNUMBER = ?, "
                                    + "USERNAME = ?, "
                                    + "PASSWD = ?, "
                                    + "DATETOCHANGEPASSWD = ?, "
                                    + "ADDRESS = ?, "
                                    + "STATEREGION = ?, "
                                    + "COUNTRY = ?, "
                                    + "USERSTATUS = ?, "
                                    + "TELEPHONE = ?, "
                                    + "DATEUSERADDED = ?, "
                                    + "USEREXPIREDATE = ?, "
                                    + "DATEUSERLOCKED = ?, "
                                    + "CITY = ?, "
                                    + "EMAIL = ?, "
                                    + "DESCRIPTION = ? "
                        + "WHERE USERID = " + id;

                ps = conn.prepareStatement(SqlStatement);

                ps.setString(1, settingsMap.get("USERID"));
                ps.setString(2, settingsMap.get("GROUPID"));
                ps.setString(3, settingsMap.get("SPECIALNUMBER"));
                ps.setString(4, settingsMap.get("USERNAME"));
                ps.setString(5, passwdConvert(settingsMap.get("PASSWD")));
                ps.setDate(6, toDate(settingsMap.get("DATETOCHANGEPASSWD")));
                ps.setString(7, settingsMap.get("ADDRESS"));
                ps.setString(8, settingsMap.get("STATEREGION"));
                ps.setString(9, settingsMap.get("COUNTRY"));
                ps.setString(10, settingsMap.get("USERSTATUS"));
                ps.setString(11, settingsMap.get("TELEPHONE"));
                ps.setDate(12, toDate(settingsMap.get("DATEUSERADDED")));
                ps.setDate(13, toDate(settingsMap.get("USEREXPIREDATE")));
                ps.setDate(14, toDate(settingsMap.get("DATEUSERLOCKED")));
                ps.setString(15, settingsMap.get("CITY"));
                ps.setString(16, settingsMap.get("EMAIL"));
                ps.setString(17, settingsMap.get("DESCRIPTION"));

                ps.executeUpdate();

                conn.commit();
                committed = true;
            }
            finally 
            {
                if (!committed) {
                    conn.rollback();
                }
            }
        } finally {
            /* Release the resources */
            ps.close();
            conn.close();
        }
        return result;
    }

Right now I cannot test the SQL query. Can you tell me is it valid and how I can optimize the SQL query for performance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:35:32+00:00Added an answer on June 8, 2026 at 9:35 am

    The only improvement you can make is put the id as ‘?’ also:

    UPDATE USERS "
                                + "SET "
                                    + "USERID = ?, "
                                    + "GROUPID = ?, "
                                    + "SPECIALNUMBER = ?, "
                                    + "USERNAME = ?, "
                                    + "PASSWD = ?, "
                                    + "DATETOCHANGEPASSWD = ?, "
                                    + "ADDRESS = ?, "
                                    + "STATEREGION = ?, "
                                    + "COUNTRY = ?, "
                                    + "USERSTATUS = ?, "
                                    + "TELEPHONE = ?, "
                                    + "DATEUSERADDED = ?, "
                                    + "USEREXPIREDATE = ?, "
                                    + "DATEUSERLOCKED = ?, "
                                    + "CITY = ?, "
                                    + "EMAIL = ?, "
                                    + "DESCRIPTION = ? "
                        + "WHERE USERID = ?";
    

    And of course add a set decleration:

     ps.setInt(18, id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Java code which is used for JSF pagination: public List<ActiveSessionObj> list(int
i have written a method in java like this public boolean ADD(String ID,String Name,String
I have this java servlet that grabs information from a form, I need to
I have an URL which will call a method my method in Java. It
Why does Java not have a file copy method? This seems like such an
Context I have this piece of Java Code btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent
I will use Java as an example, but this question really applies across all
Using Java, I have a method which I'm calling with method.invoke that returns a
Coming from the Java world, in which there are no typedefs, I have a
i have this java code: ArrayList<MessageMap> ids = getNewMail(UserID, type, maxIdMessage); Message[] message =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.