r/programming • • Sep 15 '20

Java 15 released!

https://jdk.java.net/15/
214 Upvotes

130 comments sorted by

View all comments

50

u/[deleted] Sep 15 '20

I don't use it anymore, but boy am I happy because it finally got multiline strings (text blocks). Writing a raw SQL will be so much easier and readable.

-5

u/x6060x Sep 15 '20

I'm not sure if you are joking. Especially without the /s tag.

1

u/Prod_Is_For_Testing Sep 16 '20

Very useful for database generation and automation.

-1

u/x6060x Sep 16 '20

When I hear "raw sql query" the first question that pops in my mind is sql injection. How do you handle it? I am not saying there shouldn't be sql in the code, I was surprised of the 'raw" part

7

u/[deleted] Sep 16 '20

There are two options, the sql query is static and doesn't change. Or it's a prepared statement and they use bind parameters correctly. Either way, I'm not sure why raw sql immediately means sql injection to you.

6

u/nutrecht Sep 16 '20

He means "SELECT * FROM foo WHERE id =?"

That's raw SQL. But still uses prepared statement. SQL injection was never really a 'thing' in the Java world (unless you really don't know about it obviously) because even the earliest versions had prepared statements.

0

u/[deleted] Sep 16 '20

[deleted]

1

u/josenunocardoso Sep 16 '20

which makes his comment correct?

3

u/Prod_Is_For_Testing Sep 16 '20

The other guy made good points: static queries and argument bindings.

There’s another that many people don’t consider depending on their line of work. Sql injection doesn’t always matter. If you’re making a web facing user portal, then yes it matters. If you’re making a dev tool for sys admins, it doesn’t because they already have the rights to nuke a DB

0

u/[deleted] Sep 16 '20

[deleted]

4

u/Atulin Sep 16 '20

While ORMs are great for simple CRUD with joins and stuff, they don't really support things like stored procedures, or even views all that wall. And if you have a code-first approach and want to have a procedure in your migration, you have to hand-write it.

3

u/nutrecht Sep 16 '20

While ORMs are great for simple CRUD with joins and stuff

So is plain SQL. Whenever stuff gets complex you hand-written SQL that is checked with the query planner is almost always better and easier to maintain than an ORM.

Secondly; ORMs get used as an excuse to not even look at the generated SQL anymore. In my 20 years experience as a Java dev, pretty much every implementation I came across suffered from thge N + 1

You're much better off using a simple object mapper togeter with plan SQL, or something like JOOQ IMHO.

0

u/[deleted] Sep 16 '20

[deleted]

2

u/Prod_Is_For_Testing Sep 16 '20

Most companies build systems around the database, not the code. So it’s very common, and even encouraged, to integrate existing procs in the code

1

u/Prod_Is_For_Testing Sep 16 '20

ORMs are not designed to build a database at runtime. For that, you need custom scripts in the code

3

u/TheIncorrigible1 Sep 16 '20

Have you never used a migration toolset within an ORM? Your opinions sound ancient.