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 6054731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:11:09+00:00 2026-05-23T08:11:09+00:00

I need to update a query on comparing two values in two diff tables,

  • 0

I need to update a query on comparing two values in two diff tables, if there is a match then update and also prompt me if there is any duplicate values in both the tables…

here is my code:

<%@ page import="java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver");%>
<HTML>
<HEAD>
<script type="text/javascript" align="right">
document.write("<p>" + Date() + "</p>");
</script>
</head>
    <BODY bgcolor="#99CCFF">
        <p>&nbsp;</p>

<br>

        <%
       // ResultSet resultset;
        String connectionURL = "jdbc:oracle:thin:@localhost:1521:xe";
        String driver = "oracle.jdbc.driver.OracleDriver";
        String user = "hr";
        String pass = "hr";
        String value1 = request.getParameter("value1");
        String value2 = request.getParameter("value2");
        String value3 = request.getParameter("value3");
        String value4 = request.getParameter("value4");



        Connection connection = null;
        PreparedStatement pstatement = null;
        try {
            Class.forName(driver).newInstance();
           connection = DriverManager.getConnection(connectionURL, user, pass);


         pstatement = connection.prepareStatement("update Table1 set value1 ='"+ value1+"',value2='"+value2+"',value3 = '"+value3+"',value4 = '"+value4+"' where SerialNo in(select DB.SerialNo from Table1 DB, Table2 OUT where OUT.SerialNo = DB.SerialNo and DB.Transaction_Status = 'IN')");
         pstatement.executeUpdate();


           %>
            <br><br>
    <TABLE align="center" style="background-color: #efefef;"WIDTH="30%" border="1">
        <tr><th>Order Issued, Database Updated Successfully</th></tr>
    </TABLE>
       <br><br>
           <%
             pstatement.close();
             }
  catch(ClassNotFoundException e){
  out.println("Couldn't load database driver: " + e.getMessage());
  }
  catch(SQLException e){
  out.println("SQLException caught: " + e.getMessage());
  }
  catch (Exception e){
  out.println("AnyException: " +e.getMessage());
  }
  finally {
  // Always close the database connection.
  try {
  if (connection != null) connection.close();
  }
  catch (SQLException ignored){
  out.println(ignored);
  }
  }


        %>
 </BODY>
</HTML>

This code is working fine, It is updating if there is match, Now I need to prompt if there is any duplicate values in tables, The Program should prompt me if there a duplicates values….Please can anyone help me how to do this???

Thanks in advance,
Sailaja.

  • 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-05-23T08:11:10+00:00Added an answer on May 23, 2026 at 8:11 am

    You can catch the DuplicateKeyException after the end of the try block

    catch(DuplicateKeyException)
    {
    –Your code here to display for duplicate key entry
    }

    Happy coding 🙂

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

Sidebar

Related Questions

I need an update query to set the null values with another value in
I need to update a group of cells by inserting the same two characters
I need to update a field (which is currently empty) based on a match
I need write an update statement that used multiple tables to determine which rows
i have 2 tables table1: num,X,Y table2: num,X,Y i need to update X and
I need this update query to run on both SQL Server and Oracle. Our
I need to continuously update and query a mysql database (and I don't think
I need to write a SQL update query. I want to update where workorder=12300000
I need an example of an update query using WMI. I have searched but
Hello all, I need to create a query for house search, that would match

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.