PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] How to create 'update' using multiple 'set' methods

 October 24, 2022     java, jooq, sql-update     No comments   

Issue

Synopsis: I'm trying to create an SQL update using jOOQ

DSL.using(connection)
.update(DSL.table("dogs"))
.set(DSL.field("age"), DSL.field("age").add(1))
.set(DSL.field("rabies"), "true")
.where(DSL.field("id").eq("Kujo"))
.execute();

Issue:

The method set(Field<Object>, Object) is ambiguous for the type UpdateSetFirstStep<Record>

Question: How do I create this update using jOOQ?


Solution

You ran into this problem: Reference is ambiguous with generics

Fixing your query

It's always a good idea to attach data types with your jOOQ expressions. In your particular case, you can work around the problem by specifying things like:

DSL.field("age", SQLDataType.INTEGER)

Or, shorter, with the usual static imports:

field("age", INTEGER)

Using the code generator

However, jOOQ is best used with its code generator, see also this article here. Not only will you avoid problems like these, but you also get compile time type safety (of data types and meta data), advanced features like implicit joins and much more.

Your query would then look like this:

DSL.using(connection)
   .update(DOGS)
   .set(DOGS.AGE, DOGS.AGE.add(1))
   .set(DOGS.RABIES, true)
   .where(DOGS.ID.eq("Kujo"))
   .execute();


Answered By - Lukas Eder
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing