troubleshooting Question

Jdbc insert not inserting.

Avatar of mwari
mwari asked on
8 Comments1 Solution307 ViewsLast Modified:
Hi experts, I have a test class trying to insert data into db. It does not insert when I use jdbc, but only via the SQL commands on  sqlplus command line. Here is the test class:

import java.sql.*;
import java.util.Map;
import java.util.*;

public class Test {
    private int count;
    private static Connection con;
    private static String createString;
    private static ResultSet rs;
    private String query;
    /** Creates a new instance of Test */
    public Test() {
     * @param args the command line arguments
    public static void main(String[] args) {
        Test test= new Test();
        com.alindigo.costrecovery.jdbcUtilities.Insert insert = new  com.alindigo.costrecovery.jdbcUtilities.Insert();
        String url = "";
        try {
        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
        Statement pstmt =null;
        try {
            con = DriverManager.getConnection(url,"dace", "dace");
            pstmt = con.createStatement();
        } catch (SQLException se) {
            System.out.println("We got an exception while creating a statement:" +
            "that probably means we're no longer connected.");
        int m = 0;
        try {
            m = pstmt.executeUpdate("insert into daceaccount select Dates, Amount, Transaction, Reference from csvfile WHERE NOT EXISTS (SELECT Amount from daceaccount where daceaccount.Reference=csvfile.Reference and daceaccount.Dates=csvfile.Dates and csvfile.Amount=daceaccount.Amount)");
        } catch (SQLException se) {
            System.out.println("We got an exception while executing our query:" +
            "that probably means our SQL is invalid");
        System.out.println("Successfully modified " + m + " rows.\n");
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros