Hi, i need help on updating data in mysql using JDBC since im using java.i want to send data from arraylist and it seems and error when i run it.below is my code for update.

private void update(ArrayList<String> list, int uid)
   {
       try
	  {
	      Connection con=null;
              Class.forName ("com.mysql.jdbc.Driver").newInstance ();
	      con= DriverManager.getConnection("jdbc:mysql://localhost/t-way","root","");
	      PreparedStatement ps = con.prepareStatement("UPDATE `input` SET `check`=1, `output`=?  WHERE `check`=0 AND `userid`=?");
	 ps.setArray(1,list);
	 ps.setInt(2,uid);
	 ps.executeUpdate();
         ps.close();
	 con.close();

	  }

 catch (Exception e)
	  {
	     System.err.println ("Cannot connect to database server "+ e.getMessage());
	  }
  }

Error:setArray in java.sql.preparedstatement cannot to be applied to ArrayList
in database,output variable is LongBlob.if i use setBlob also got error.

Do u have any idea?i really2 stuck here

The first clue is the type of Array you are using. You should be using an implementation of java.sql.Array, not java.util.ArrayList. Check the javadocs on its use, and you will probably get a little further.

The first clue is the type of Array you are using. You should be using an implementation of java.sql.Array, not java.util.ArrayList. Check the javadocs on its use, and you will probably get a little further.

is there any changing of data?

probably better would be start with Vector (in future is possible to directly sets as dataSource for JTable)

each line is

Vector<Object> myVector = new Vector<Object>();

where wildCard Object speak about variable contents for every of Elements, if Elementscontains same Data Type and structure for example you'd store String value or Integer or Double .... then replace Object with correct Data Type, sure you don't need Casting, you can leave it, but this definitions are correct,

this vector you MUST reinicialize before new usage just and only

myVector = new Vector<Object>();

, don't remove Elements if you want to add value from 1D Vector to the 2D Vector

2D array you have to add to

Vector<Vector<Object>> myVct = new Vector<Vector<Object>>();

Edited 5 Years Ago by mKorbel: n/a

probably better would be start with Vector (in future is possible to directly sets as dataSource for JTable)

each line is

Vector<Object> myVector = new Vector<Object>();

where wildCard Object speak about variable contents for every of Elements, if Elementscontains same Data Type and structure for example you'd store String value or Integer or Double .... then replace Object with correct Data Type, sure you don't need Casting, you can leave it, but this definitions are correct,

this vector you MUST reinicialize before new usage just and only

myVector = new Vector<Object>();

, don't remove Elements if you want to add value from 1D Vector to the 2D Vector

2D array you have to add to

Vector<Vector<Object>> myVct = new Vector<Vector<Object>>();

yet,i still have a problem in PreparedStatement isnt it?

ive settle this problem by using String. i convert arraylist to string.seems ok but dont know in future!!!

try{
                  for(int b=0;b<ar.size();b++){
                     String qry ="UPDATE 'panjang_jalan' SET 'bb'=?";
                     psmnt1 = (PreparedStatement) Koneksi.conn.prepareStatement(qry);
                     psmnt1.setArray(1, ar.get(b));
                     psmnt1.executeUpdate();                     
                     System.out.println("success");
                  }
               }catch(Exception e){
                   e.printStackTrace();
                   System.out.println("failed");
               }       

I want to send arraylist object into mysql column table, I try this code.I have import java.sql.Array. But I found error "method setArray in interface java.sql.PreparedStatement can't be applied to given typed required: int,java.sql.Array found int,java.lang.Object. " please help me,..

This question has already been answered. Start a new discussion instead.