1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.databases.blog;
17
18 import java.sql.*;
19
20 public class StoredProcedures {
21 public static void selectTwoSetsOfTwoAuthors(int p1, int p2, ResultSet[] rs1, ResultSet[] rs2) throws SQLException {
22 try (Connection conn = DriverManager.getConnection("jdbc:default:connection")) {
23 PreparedStatement ps1 = conn.prepareStatement("select * from author where id in (?,?)");
24 ps1.setInt(1, p1);
25 ps1.setInt(2, p2);
26 rs1[0] = ps1.executeQuery();
27 PreparedStatement ps2 = conn.prepareStatement("select * from author where id in (?,?)");
28 ps2.setInt(1, p2);
29 ps2.setInt(2, p1);
30 rs2[0] = ps2.executeQuery();
31 }
32 }
33
34 public static void insertAuthor(int id, String username, String password, String email) throws SQLException {
35 try (Connection conn = DriverManager.getConnection("jdbc:default:connection")) {
36 PreparedStatement ps = conn.prepareStatement("INSERT INTO author (id, username, password, email) VALUES (?,?,?,?)");
37 ps.setInt(1, id);
38 ps.setString(2, username);
39 ps.setString(3, password);
40 ps.setString(4, email);
41 ps.executeUpdate();
42 }
43 }
44
45 public static void selectAuthorViaOutParams(int id, String[] username, String[] password, String[] email, String[] bio) throws SQLException {
46 try (Connection conn = DriverManager.getConnection("jdbc:default:connection")) {
47 PreparedStatement ps = conn.prepareStatement("select * from author where id = ?");
48 ps.setInt(1, id);
49 ResultSet rs = ps.executeQuery();
50 rs.next();
51 username[0] = rs.getString("username");
52 password[0] = rs.getString("password");
53 email[0] = rs.getString("email");
54 bio[0] = rs.getString("bio");
55 }
56 }
57 }