Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38422 > unrolled thread

Is there a SQL hashmap?

Started by"Eric Douglas" <eric.douglas@1:261/38.remove-i5b-this>
First post2018-06-26 09:03 -0500
Last post2018-06-26 12:23 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Is there a SQL hashmap? "Eric Douglas" <eric.douglas@1:261/38.remove-i5b-this> - 2018-06-26 09:03 -0500
    Re: Is there a SQL hashmap? "Arne Vajhøj" <arne vajhøj@1:261/38.remove-i5b-this> - 2018-06-26 12:23 -0500

#38422 — Is there a SQL hashmap?

From"Eric Douglas" <eric.douglas@1:261/38.remove-i5b-this>
Date2018-06-26 09:03 -0500
SubjectIs there a SQL hashmap?
Message-ID<5B329ADB.1161.ucljprogr@castlerockbbs.com>
From: Eric Douglas <e.d.programmer@gmail.com>

I'm using JDBC with java.sql.PreparedStatement on SQL Server 2012.

I'm trying to write a translate that says "select <map value> (where
table1.field = <map key>) from table1"

Getting a bit tired of writing it as "select iif(table1.field = 'first
key','first value',iif(table1.field = 'second key','second value','default'))
from table1"

Just a better syntax to do such a thing within the SQL, or a way to pass the
values as a parameter?  Ideally I would just create a table and write the
values there and join that table, but I don't want to alter that database which
 was created by our third party application.

I was hoping to avoid the other option, modifying the code that gets the
results of the query to translate that result field, since this section of the
code is generic - used to send the results of multiple queries to a
spreadsheet.

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)

[toc] | [next] | [standalone]


#38423

From"Arne Vajhøj" <arne vajhøj@1:261/38.remove-i5b-this>
Date2018-06-26 12:23 -0500
Message-ID<5B329ADB.1162.ucljprogr@castlerockbbs.com>
In reply to#38422
  To: Eric Douglas
From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= <arne@vajhoej.dk>

On 6/26/2018 12:03 PM, Eric Douglas wrote:
> I'm using JDBC with java.sql.PreparedStatement on SQL Server 2012.
>
> I'm trying to write a translate that says "select <map value> (where
> table1.field = <map key>) from table1"
>
> Getting a bit tired of writing it as "select iif(table1.field =
> 'first key','first value',iif(table1.field = 'second key','second
> value','default')) from table1"
>
> Just a better syntax to do such a thing within the SQL, or a way to
> pass the values as a parameter?  Ideally I would just create a table
> and write the values there and join that table, but I don't want to
> alter that database which was created by our third party
> application.
>
> I was hoping to avoid the other option, modifying the code that gets
> the results of the query to translate that result field, since this
> section of the code is generic - used to send the results of multiple
> queries to a spreadsheet.


I think you already considered the two most obvious options.

1) Database table and JOIN.
2) Translate in application code.

Note that #2 is a lot more elegant if using JPA than plain JDBC.

String mappedfield1 = valmap.get(rs.getString("field1"));

vs:

@Column
private String field1;
...
public String getField1() {
     return field1;
}
public String getMappedField1() {
     return valmap.get(field1);
}

Arne

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web