Java ArrayList <> insert into Oracle DB

1.9k views Asked by At

I need to insert an ArrayList into Oracle XE. Here's what I am sweating on:

    ArrayList <Double> array = new ArrayList<Double>();
    array.add(10.2);
    array.add(11.2);
    array.add(12.2);
    array.add(1.2);
    array.add(10.2);
    array.add(10.2);
    array.add(10.2);


    Connection dbConnection = null;
    Statement statement = null;
    ResultSet rows = null;
    Iterator<Double> it=array.iterator();

    String insertTableSQL = "INSERT INTO RVALUES VALUES(";


    for(int i=0;i<array.size();){

        it.next();
        i++;
    }
    insertTableSQL +=")";

    String selectTableSQL = "Select * from RVALUES";

    try {
        dbConnection = getDBConnection();
        statement = dbConnection.createStatement();

        System.out.println(insertTableSQL);

        rows = statement.executeQuery(selectTableSQL);

        while(rows.next()){
            System.out.print(rows.getInt(1)+"\t");
            System.out.println(rows.getInt(2));
        }

        statement.executeUpdate(insertTableSQL);

        System.out.println("Record is inserted into DBUSER table!");

It says "ORA-00936: missing expression". I am re-doing this so long...that I am lost. Any help on this one will be very appreciated.

2

There are 2 answers

0
Milena Georgieva On

@Christian Kuetbach, thanks a lot for the link. It was helpful.

Issue solved.

P.S. I do have an idea what and how SLQ is. This was just an easy example, which to be used in more complex project! Anyway, good day to all :-)

0
Christian Kuetbach On

Don't do it this way.

Create a PreparedStatement and make a Batch-Update.

This will be faster and more secure.