java - Compare the values in two tables and insert into the second table the value fetched from the first table -


pls help! i've 2 tables: info , message info has columns :

id  name   location   description  1    abc    def         ghijg      123 2    xyz    wqk        fdgbf       234 3    tuv    ghn        hndbd       345 

message had columns :

id   text              created_at 1    hi        123             12345 1    hey       123             12345 2    hello     234             98765 

i want insert new values message , set value of id(in message) corresponding value of id of info. example shows id 1 in message tells row corresponds info table's id 1.

i'm writing java code insert new values message.

my tables huge i'm storing id , name info arraylist , comparing id arraylist , name values null. im using loop iterating through arraylist , compare name value name value im calling twitter , insert message. code is:

for(bank v: bankid){        if(v.getname()== null || v.getname().equals(name)){         if(v.getname().equals(name)){             system.out.println(v.getid());             ps.setstring(1,v.getid());         }     } } 

insert id value fetched info table message along other values.

i'm unable insert new values. how do that? i'm using statement:

 string sql = "insert message(id,text,from,craeted_at) values (id,?,?,?)";             preparedstatement ps = conn.preparestatement(sql); 

please help! thanks!

first of all-

if(v.getname()== null || v.getname().equals(name)) 

this line can give null pointer exception. change check as

if(v.getname()!= null || name.equals(v.getname())) 

then insert values prepared statement ex.

      ps.setint(1,23);       ps.setstring(2,"roshan");       ps.setstring(3, "ceo");       ps.executeupdate(); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -