How to compare two tables, and insert values which r not in one table to another table?

How to compare two tables, and insert values which r not in one table to another table?

Hi

I need to compare two tables MainTable and OUTTable, The maintable may not have all the data so...if outtable have new data just insert the values to main_table...

here is my sql query

insert into Main_Table MT (MT.serialno) values (Select SerialNo Main_Table MT from where not exists (select SerialNo from OUT_Table OT where OT.SerialNo = MT.SerialNo));

here is my code:

<%@ page import="java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver");%>
<HTML>

    <BODY bgcolor="#99CCFF">
        <p>&nbsp;</p>
<p><img src="SingtelLogoBanner.gif" width="87" height="25"> </p>
<center>
<td align="right" width=37> <strong><img title="Go back" src="Undo.gif" width="20" height="20" onClick="javascript:history.back()" style="vertical-align:middle;" onMouseOver="this.style.cursor='hand';"></strong>
<td align="right" width=38> <strong><img title="Print it" src="Print.gif" width="20" height="20" onClick="javascript:window.print()" style="vertical-align:middle;" onMouseOver="this.style.cursor='hand';">
        </strong>
</center>
<H1 align="center">Inventory</H1>
        <%

        String connectionURL = "jdbc:oracle:thin:@localhost:1521:scott";
        String driver = "oracle.jdbc.driver.OracleDriver";
        String user = "root";
        String pass = "root";
        Connection connection = null;
        PreparedStatement pstatement = null;
        ResultSet resultset;
        int i = 1;

            Class.forName(driver).newInstance();
           connection = DriverManager.getConnection(connectionURL,user,pass);



             String queryString = ("insert into Main_Table MT (MT.serialno) values (Select SerialNo from Main_Table MT where not exists (select SerialNo from OUT_Table OT where OT.SerialNo = MT.SerialNo))");
             resultset = pstatement.executeQuery(queryString);
        %>

    </BODY>
</HTML>

This query is selecting all the values which r not in maintable...but not inserting into the main table using jsp. I am doing this program using JSP. Please can you give me the code to insert the values into maintable. Please help me out. Iam stuck here.

Thanks in advance Lissy.

View Answers









Related Tutorials/Questions & Answers:
How to compare two tables, and insert values which r not in one table to another table?
how to set the tables one is left and another one is right - JSP-Servlet
Advertisements
can i insert values into two tables by a query - JDBC
how to store array values into two different tables in java?
how to do two database tables in one page?
how to get values for same column name from two different tables in SQL
Data fetch from multiple SQL tables - Hibernate
Join the two tables in sql
how to insert one table to anothere table
SQL Server row comparison using two tables
take data from one table and insert same in another
ModuleNotFoundError: No module named 'btc-yet-another-tables'
tables in oracle 10g
Comparing tables
how to add the two tables in same row when generating pdf file from jsp - JSP-Servlet
search in Two Tables to Find data and view by jsp
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
merge tables in sql using union
sql query to get data from two tables
CSV tables
Combine Two Tables(Purchase and Sales) and getting Current Stock
update one table from another table
Joining tables using criteria
types of relationships in tables
Join tables in the specific database
Nest tables within tables
Mysql Join 3 Tables
I cant get values in MS acces in tables
what is the jsp coding to insert a data in database tables
copying data from one table to another
how to compare text in two jTextarea
Natural Join / joining two tables
how to count unique and duplicate values from one table in mysql?
how to get multiple hyperlink values from a table column to another jsp file?
how to insert the bulk data into the data base from the table of jsp page to another jsp page
PHP Join Tables
tables for layout
tables for layout
Cross Join Tables in a Specific Database
Copy One Database Table to Another
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
Retrieving Tables from a Database
Query for gathering info from 3 tables with condition depended on 4th table
retrieve the records from one table to another table by using cursors
Mysql List Tables
how to insert a summary values in grid
use tables to structure forms
use tables to structure forms

Ads