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

  • SEARCH
  • Home
  • 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 8893187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:11:03+00:00 2026-06-14T23:11:03+00:00

Can i have more than one preparestatement in one .jsp file? I´m trying to

  • 0

Can i have more than one preparestatement in one .jsp file? I´m trying to execute this “jsp file”, but this code doesnt work for me.
Something like this:

<%
    String login = request.getParameter("login");
    String pwd = request.getParameter("password");
    String name = request.getParameter("name");

    Connection connection = null;
    PreparedStatement pstatement = null;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    int updateQuery = 0;
    if (login != null && password != null && full_name != null && ulevel != null && team_id != null) {
        if (login != "" && password != "" && full_name != "" && ulevel != "" && team_id != "") {
            try {
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/<mydatabase>", "<mylogin>", "<mypwd>");
                String queryString_1 = "INSERT INTO users (login,password) VALUES (?, ?)";
                pstatement = connection.prepareStatement(queryString_1);
                pstatement.setString(1, login);
                pstatement.setString(2, password);
                updateQuery = pstatement.executeUpdate();
                String queryString_2 = "INSERT INTO members (name) VALUES (?)";
                pstatement = connection.prepareStatement(queryString_2);
                pstatement.setString(1, name);
                updateQuery = pstatement.executeUpdate();
                if(updateQuery_1 != 0 && updateQuery_2 != 0) {
                   response.sendRedirect("index.jsp");
                }
            } catch (Exception ex) {
                out.println("Unable to connect to database.");
                } finally {
                pstatement.close();
                connection.close();
            }
        } 
    } 
%>
  • 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-14T23:11:04+00:00Added an answer on June 14, 2026 at 11:11 pm

    You may have as many PreparedStatements as you need.

    To improve your code:
    1. You must declare int updateQuery_1 = 0 and updateQuery_2 = 0.
    2. You must use updateQuery_1 = pstatement.executeUpdate(); and updateQuery_2 = pstatement.executeUpdate(); on your two different sql statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can an if statement have more than one then statements? # this works a
Can I have more than one XmlElement on property of a class? For example:
Can a Objective c interface have more than one implementation? Example I could have
How can one have more than a Wizard control on the same page without
I have an Ajax request that can return more than one valid value, so
I have following query which take more than a minute to execute, how can
If we can have more than one .config files, we can share one config
I'm given a graph which can have more than one arch between 2 nodes.
The question is a very simple one, can you have more than one index
I have a table, SUBSCRIBERS , in which I can have more than one

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.