Download Jar. Uses 1780K of libraries. Click here for Pure Java version (890L/6K).
1 | !7 |
2 | |
3 | lib 1011900 // h2 |
4 | |
5 | static Connection conn; |
6 | |
7 | import java.sql.*; |
8 | import java.lang.reflect.Array; |
9 | |
10 | p { |
11 | Class.forName("org.h2.Driver"); |
12 | conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/test", "sa", ""); |
13 | |
14 | print(symbolToID(print("hello")); |
15 | print(symbolToID(print("world")); |
16 | |
17 | conn.close(); |
18 | } |
19 | |
20 | static int symbolToID(S symbol) ctex { |
21 | PreparedStatement statement = conn.prepareStatement("select id from symbol where name=?"); |
22 | statement.setString(1, symbol); |
23 | ResultSet rs = statement.executeQuery(); |
24 | try { |
25 | if (rs.next()) |
26 | ret rs.getInt("id"); |
27 | } finally { |
28 | rs.close(); |
29 | } |
30 | |
31 | statement = conn.prepareStatement("insert into symbol set name=?", |
32 | statement.RETURN_GENERATED_KEYS); |
33 | statement.setString(1, symbol); |
34 | statement.executeUpdate(); |
35 | |
36 | ResultSet generatedKeys = statement.getGeneratedKeys(); |
37 | try { |
38 | assertTrue(generatedKeys.next()); |
39 | ret generatedKeys.getInt(1); |
40 | } finally { |
41 | generatedKeys.close(); |
42 | } |
43 | } |
Began life as a copy of #1011903
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1011905 |
Snippet name: | Connect to H2 server, insert stuff (OK) |
Eternal ID of this version: | #1011905/14 |
Text MD5: | 7e5d7a3ca42bb3ae0466e0d6b0f49f48 |
Transpilation MD5: | f047c5d308166b5537bf0b9006786c53 |
Author: | stefan |
Category: | javax / h2 database |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-11-09 10:58:08 |
Source code size: | 1013 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 423 / 1025 |
Version history: | 13 change(s) |
Referenced in: | [show references] |