Share on Google+Share on Google+

lissy
How to compare two tables, and insert values which r not in one table to another table?
0 Answer(s)      5 years and 7 months ago
Posted in : JSP-Servlet

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.

Ads

View Answers









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values

Ads

 
Advertisement null

Ads