• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading url response and writing it to database

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 have been trying this program fr 2 days now please help someoneU have a url whose result is somewhat likeUsername1= xxx,username2=yyy.....40 values.....We need to read the response of the url and insert it in database....where already a table is present with all keys(username1,username2,..) as header fields...we need to insert their values dynamically...the keys may not be in the same order in database as in url response..... i was able to get response and store it in a string array but am unable to get any idea on how to insert only values dynamically ...............Ill be very thankful if someone can help
 
Ranch Hand
Posts: 49
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed. Please format your posts to make easily readable.

As for your question, what I understand is that you have a Servlet in which you received and process 40 query string items and you'd like to store the values in a database where the same keys exist. So far you've parsed the key-value pairs into an Array. If this is correct, in the simplest form, you'll ought to create a middle tier class in which you use JDBC to connect to your database and execute an UPDATE command. I recommend using database stored procedures instead of writing the SQL command in your database.
 
Ranch Hand
Posts: 33
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
show some code,lets see what you've done.....
 
Jaikiran mathukumalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry....first time posting in a blog so i do not know all the rules,well here's the code i could write so far




(The url response would be like

username1=sudeep,username2=kiran,username3=jai,username4=jaikiran.......)



and the table would have username1,username2,username3,username4......as headers,i need to insert the values(i.e sudeep,kiran,jai...) according to their respective keys.

Now i have tried putting them into a map because i thought i could make them into key,values and insert the values into database with respect to their keys but i am unable to get any idea on how to do it.

Hope this information is enough,i will provide more if asked




 
Amir Keibi
Ranch Hand
Posts: 49
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's better.
First thing first, it seems that the key-value pairs aren't in the URL but in the content of the HTTP response (you're parsing the content).
Like I mentioned, in order to update the database, the bare minimum you need to do is to use JDBC and execute an "Update" SQL command for each pair which updates the values.

Are you facing any specific problem or you just don't know how to connect to DB from within your code?
 
Jaikiran mathukumalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What? No i do know how to insert them into database.The key's are already present in the database tables as header fields of the table.The table was created like.

Create table value_1(username1 char(10),........)

Now what i need to do is match the values with their respective keys and insert them in a way that they are under their key , which is what i am unable to figure out how.

Can you please write me down a code or just give me a rough idea on how to do it?
 
Amir Keibi
Ranch Hand
Posts: 49
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SQL problem then.

You have two options:

1- Not very good option is to write 40 different UPDATE commands:

Sudo sample:


2- Create a dynamic UPDATE command (could have performance implication):

Sudo sample:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic