Пример получения из базы Oracle единственного значения из таблицы Oracle (PreparedStatement)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| private void myMethodExample(String userLogin){
String sql;
sql = "select tn.col1, tn.col2, tn.col3 from table_name tn where login = '" + userLogin + "'";
String result1;
String result2;
String result2;
PreparedStatement st = null;
ResultSet rs = null;
st = DBUtils.getDBTransaction().createPreparedStatement(sql,1);
try {
rs = st.executeQuery();
if (rs != null && rs.next()) {
result1 = rs.getString(1);
result2 = rs.getString(2);
result3 = rs.getString(3);
}
}
catch (Exception ex){
System.out.println("Exception1 Occured " + ex.getMessage());
}
finally {
try {
pst.close();
rs.close();
}
catch (Exception e) {
System.out.println(" Exception2 Occured " + e.getMessage());
}
}
}
|