You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Fixed bug where Statement.setMaxRows() was a global setting. Now
limited to just itself.
- Changed LargeObject.read(byte[],int,int) to return the actual number
of bytes read (used to be void).
- LargeObject now supports InputStream's!
- PreparedStatement.setBinaryStream() now works!
- ResultSet.getBinaryStream() now returns an InputStream that doesn't
copy the blob into memory first!
- Connection.isClosed() now tests to see if the connection is still alive
rather than if it thinks it's alive.
// For large inserts, a PreparedStatement is more efficient, because it
100
101
// supports the idea of precompiling the SQL statement, and to store
101
102
// directly, a Java object into any column. PostgreSQL doesnt support
@@ -112,7 +113,7 @@ public void doexample() throws SQLException
112
113
ps.executeUpdate(); // executeUpdate because insert returns no data
113
114
}
114
115
ps.close(); // Always close when we are done with it
115
-
116
+
116
117
// Finally perform a query on the table
117
118
System.out.println("performing a query");
118
119
ResultSetrs = st.executeQuery("select a, b from basic");
@@ -126,7 +127,7 @@ public void doexample() throws SQLException
126
127
}
127
128
rs.close(); // again, you must close the result when done
128
129
}
129
-
130
+
130
131
// Now run the query again, showing a more efficient way of getting the
131
132
// result if you don't know what column number a value is in
132
133
System.out.println("performing another query");
@@ -140,7 +141,7 @@ public void doexample() throws SQLException
140
141
//
141
142
intcol_a = rs.findColumn("a");
142
143
intcol_b = rs.findColumn("b");
143
-
144
+
144
145
// Now we run through the result set, printing out the result.
145
146
// Again, we must call .next() before attempting to read any results
146
147
while(rs.next()) {
@@ -150,11 +151,22 @@ public void doexample() throws SQLException
150
151
}
151
152
rs.close(); // again, you must close the result when done
152
153
}
153
-
154
+
155
+
// Now test maxrows by setting it to 3 rows
156
+
st.setMaxRows(3);
157
+
System.out.println("performing a query limited to "+st.getMaxRows());
158
+
rs = st.executeQuery("select a, b from basic");
159
+
while(rs.next()) {
160
+
inta = rs.getInt("a"); // This shows how to get the value by name
161
+
intb = rs.getInt(2); // This shows how to get the value by column
162
+
System.out.println(" a="+a+" b="+b);
163
+
}
164
+
rs.close(); // again, you must close the result when done
165
+
154
166
// The last thing to do is to drop the table. This is done in the
155
167
// cleanup() method.
156
168
}
157
-
169
+
158
170
/**
159
171
* Display some instructions on how to run the example
160
172
*/
@@ -164,22 +176,22 @@ public static void instructions()
164
176
System.out.println("Useage:\n java example.basic jdbc:postgresql:database user password [debug]\n\nThe debug field can be anything. It's presence will enable DriverManager's\ndebug trace. Unless you want to see screens of items, don't put anything in\nhere.");
165
177
System.exit(1);
166
178
}
167
-
179
+
168
180
/**
169
181
* This little lot starts the test
170
182
*/
171
183
publicstaticvoidmain(Stringargs[])
172
184
{
173
185
System.out.println("PostgreSQL basic test v6.3 rev 1\n");
174
-
186
+
175
187
if(args.length<3)
176
188
instructions();
177
-
189
+
178
190
// This line outputs debug information to stderr. To enable this, simply
0 commit comments