File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 10
10
</parent >
11
11
<groupId >py</groupId >
12
12
<artifactId >java-sql-cli</artifactId >
13
- <version >1.0 </version >
13
+ <version >1.1 </version >
14
14
<name >sql client written in java</name >
15
15
<description >sql helper</description >
16
16
Original file line number Diff line number Diff line change 6
6
import org .springframework .shell .standard .ShellComponent ;
7
7
import org .springframework .shell .standard .ShellMethod ;
8
8
import org .springframework .shell .standard .ShellOption ;
9
+ import org .springframework .util .StringUtils ;
9
10
10
11
import javax .annotation .PostConstruct ;
11
12
import javax .annotation .PreDestroy ;
@@ -72,6 +73,27 @@ public void init() {
72
73
public String exec (
73
74
@ ShellOption () String sql ,
74
75
@ ShellOption () boolean json ) {
76
+
77
+ sql = sql .trim ();
78
+ if (StringUtils .startsWithIgnoreCase (sql , "select" )) {
79
+ return execQuery (sql , json );
80
+ } else {
81
+ return execUpdate (sql );
82
+ }
83
+
84
+ }
85
+
86
+ private String execUpdate (String sql ) {
87
+ try {
88
+ int rows = stmt .executeUpdate (sql );
89
+ return "rows: " +rows ;
90
+ } catch (SQLException e ) {
91
+ e .printStackTrace ();
92
+ return "error: " + e .getMessage ();
93
+ }
94
+ }
95
+
96
+ private String execQuery (String sql , boolean json ) {
75
97
try (ResultSet rs = stmt .executeQuery (sql )) {
76
98
final ResultSetMetaData metaData = rs .getMetaData ();
77
99
final int columnCount = metaData .getColumnCount ();
You can’t perform that action at this time.
0 commit comments