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

Recommended Answers

All 9 Replies

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?

do i need to change ArrayList to Array[][]?

anyone knows how to do it?

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>>();

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?

if isn't it, then which one,

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,..

DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules

This thread is a year old. Please start your own thread for your question

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.