• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting with MYSQL Database

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Im trying to do this:

I have application connecting and getting data from Mysql database.

And i have problem to do this:



Ok, it works, but only if there is field_name2 with valueX

So when there isnt i would execute new statement with INSERT.

I know how to get data from mysql and so on, i just would request some help with already mentioned problem, check if field with given value exist, if yes update it with X in field Y, if not insert new ready entry with proper needed data.

Thanks in advance!

 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mathew Mintalm wrote:check if field with given value exist, if yes update it with X in field Y, if not insert new ready entry with proper needed data.


Yes, that's correct, that's how you would do that. Did you have some question about it?
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply

so i have to connect with database and use select statement, with try and catch exception, and in catch exception i should execute void which will create new entry (in case of exception)

?
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where exceptions would come into the process. Do a SELECT which looks for the record which may or may not be there; if that query returns zero rows then it isn't there, so do an INSERT. If the query returns a row, then do an UPDATE.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i guess i understand, could you please only show me this part of the code:

Do a SELECT which looks for the record which may or may not be there; if that query returns zero rows


?
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry... do you really not know how to execute a SELECT statement and read a row from it? That's usually the first example in any of the tutorials I ever saw.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I said i know, but i couldnt really example what did you mean with my previously quoted sentence.

do you meant something like that?

 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You actually have to try to read a row from the ResultSet.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic