0
# JDBC Core Operations
1
2
The fundamental JDBC 4.2 API for relational database access, including connection management, statement execution, and result processing. This documentation covers the core interfaces and classes for traditional JDBC database operations.
3
4
## Capabilities
5
6
### Driver Registration
7
8
The MySQL JDBC driver implementation that registers with the DriverManager for connection creation.
9
10
```java { .api }
11
package com.mysql.cj.jdbc;
12
13
public class Driver extends NonRegisteringDriver implements java.sql.Driver {
14
static {
15
try {
16
java.sql.DriverManager.registerDriver(new Driver());
17
} catch (SQLException E) {
18
throw new RuntimeException("Can't register driver!");
19
}
20
}
21
22
public Driver() throws SQLException {
23
// Required constructor
24
}
25
}
26
27
public class NonRegisteringDriver implements java.sql.Driver {
28
public Connection connect(String url, Properties info) throws SQLException;
29
public boolean acceptsURL(String url) throws SQLException;
30
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException;
31
public int getMajorVersion();
32
public int getMinorVersion();
33
public boolean jdbcCompliant();
34
public Logger getParentLogger() throws SQLFeatureNotSupportedException;
35
}
36
```
37
38
Usage:
39
40
```java
41
// Driver is auto-registered via static initializer
42
// Simply use DriverManager to get connections
43
Connection conn = DriverManager.getConnection(
44
"jdbc:mysql://localhost:3306/mydb",
45
"user",
46
"password"
47
);
48
```
49
50
### Connection Management
51
52
Core connection interface with MySQL-specific extensions for transaction management and connection state.
53
54
```java { .api }
55
package com.mysql.cj.jdbc;
56
57
import java.util.concurrent.locks.Lock;
58
59
public interface JdbcConnection extends java.sql.Connection, com.mysql.cj.MysqlConnection {
60
// Statement creation
61
Statement createStatement() throws SQLException;
62
Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException;
63
Statement createStatement(int resultSetType, int resultSetConcurrency,
64
int resultSetHoldability) throws SQLException;
65
66
PreparedStatement prepareStatement(String sql) throws SQLException;
67
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
68
throws SQLException;
69
PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
70
int resultSetHoldability) throws SQLException;
71
PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException;
72
PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException;
73
PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException;
74
75
CallableStatement prepareCall(String sql) throws SQLException;
76
CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
77
throws SQLException;
78
CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
79
int resultSetHoldability) throws SQLException;
80
81
// MySQL-specific statement creation
82
PreparedStatement clientPrepareStatement(String sql) throws SQLException;
83
PreparedStatement clientPrepareStatement(String sql, int autoGeneratedKeys) throws SQLException;
84
PreparedStatement clientPrepareStatement(String sql, int resultSetType, int resultSetConcurrency)
85
throws SQLException;
86
PreparedStatement clientPrepareStatement(String sql, int resultSetType, int resultSetConcurrency,
87
int resultSetHoldability) throws SQLException;
88
PreparedStatement clientPrepareStatement(String sql, int[] autoGeneratedKeyIndexes)
89
throws SQLException;
90
PreparedStatement clientPrepareStatement(String sql, String[] autoGeneratedKeyColNames)
91
throws SQLException;
92
93
PreparedStatement serverPrepareStatement(String sql) throws SQLException;
94
PreparedStatement serverPrepareStatement(String sql, int autoGeneratedKeys) throws SQLException;
95
PreparedStatement serverPrepareStatement(String sql, int resultSetType, int resultSetConcurrency)
96
throws SQLException;
97
PreparedStatement serverPrepareStatement(String sql, int resultSetType, int resultSetConcurrency,
98
int resultSetHoldability) throws SQLException;
99
PreparedStatement serverPrepareStatement(String sql, int[] autoGeneratedKeyIndexes)
100
throws SQLException;
101
PreparedStatement serverPrepareStatement(String sql, String[] autoGeneratedKeyColNames)
102
throws SQLException;
103
104
// Transaction management
105
void setAutoCommit(boolean autoCommit) throws SQLException;
106
boolean getAutoCommit() throws SQLException;
107
void commit() throws SQLException;
108
void rollback() throws SQLException;
109
void rollback(Savepoint savepoint) throws SQLException;
110
111
// Savepoints
112
Savepoint setSavepoint() throws SQLException;
113
Savepoint setSavepoint(String name) throws SQLException;
114
void releaseSavepoint(Savepoint savepoint) throws SQLException;
115
116
// Transaction isolation
117
void setTransactionIsolation(int level) throws SQLException;
118
int getTransactionIsolation() throws SQLException;
119
120
// Connection state
121
void close() throws SQLException;
122
boolean isClosed() throws SQLException;
123
boolean isValid(int timeout) throws SQLException;
124
125
// Database selection
126
void setCatalog(String catalog) throws SQLException;
127
String getCatalog() throws SQLException;
128
void setSchema(String schema) throws SQLException;
129
String getSchema() throws SQLException;
130
131
// Read-only mode
132
void setReadOnly(boolean readOnly) throws SQLException;
133
boolean isReadOnly() throws SQLException;
134
135
// Warnings
136
SQLWarning getWarnings() throws SQLException;
137
void clearWarnings() throws SQLException;
138
139
// Metadata
140
DatabaseMetaData getMetaData() throws SQLException;
141
142
// Type mapping
143
Map<String, Class<?>> getTypeMap() throws SQLException;
144
void setTypeMap(Map<String, Class<?>> map) throws SQLException;
145
146
// Holdability
147
void setHoldability(int holdability) throws SQLException;
148
int getHoldability() throws SQLException;
149
150
// Network timeout
151
void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException;
152
int getNetworkTimeout() throws SQLException;
153
154
// Abort
155
void abort(Executor executor) throws SQLException;
156
157
// Client info
158
void setClientInfo(String name, String value) throws SQLClientInfoException;
159
void setClientInfo(Properties properties) throws SQLClientInfoException;
160
String getClientInfo(String name) throws SQLException;
161
Properties getClientInfo() throws SQLException;
162
163
// Native SQL
164
String nativeSQL(String sql) throws SQLException;
165
166
// CLOB and BLOB creation
167
Clob createClob() throws SQLException;
168
Blob createBlob() throws SQLException;
169
NClob createNClob() throws SQLException;
170
SQLXML createSQLXML() throws SQLException;
171
172
// Array and Struct creation
173
Array createArrayOf(String typeName, Object[] elements) throws SQLException;
174
Struct createStruct(String typeName, Object[] attributes) throws SQLException;
175
176
// MySQL-specific methods
177
void changeUser(String userName, String newPassword) throws SQLException;
178
void ping() throws SQLException;
179
boolean hasSameProperties(JdbcConnection c);
180
String getStatementComment();
181
void setStatementComment(String comment);
182
boolean lowerCaseTableNames();
183
void resetServerState() throws SQLException;
184
boolean isSourceConnection();
185
boolean isSameResource(JdbcConnection c);
186
void setDatabase(String dbName) throws SQLException;
187
String getDatabase();
188
void shutdownServer() throws SQLException;
189
void setFailedOver(boolean flag);
190
191
// Connection state and monitoring
192
int getActiveStatementCount();
193
long getIdleFor();
194
boolean isServerLocal() throws SQLException;
195
String getHost();
196
String getHostPortPair();
197
Lock getLock();
198
199
// XA transaction support
200
boolean isInGlobalTx();
201
void setInGlobalTx(boolean flag);
202
203
// Server configuration
204
int getAutoIncrementIncrement();
205
int getSessionMaxRows();
206
void setSessionMaxRows(int max) throws SQLException;
207
ServerVersion getServerVersion();
208
209
// Advanced connection features
210
void setProxy(JdbcConnection proxy);
211
boolean isProxySet();
212
void abortInternal() throws SQLException;
213
CachedResultSetMetaData getCachedMetaData(String sql);
214
String getCharacterSetMetadata();
215
java.sql.Statement getMetadataSafeStatement() throws SQLException;
216
List<QueryInterceptor> getQueryInterceptorsInstances();
217
void initializeSafeQueryInterceptors() throws SQLException;
218
void unSafeQueryInterceptors() throws SQLException;
219
void initializeResultsMetadataFromCache(String sql, CachedResultSetMetaData cachedMetaData,
220
ResultSetInternalMethods resultSet) throws SQLException;
221
ClientInfoProvider getClientInfoProviderImpl() throws SQLException;
222
223
// Multi-host connection support
224
JdbcConnection getMultiHostSafeProxy();
225
JdbcConnection getMultiHostParentProxy();
226
JdbcConnection getActiveMySQLConnection();
227
228
// Internal connection management
229
boolean storesLowerCaseTableName();
230
void throwConnectionClosedException() throws SQLException;
231
void registerStatement(JdbcStatement stmt);
232
void unregisterStatement(JdbcStatement stmt);
233
void recachePreparedStatement(JdbcPreparedStatement pstmt) throws SQLException;
234
void decachePreparedStatement(JdbcPreparedStatement pstmt) throws SQLException;
235
void setReadOnlyInternal(boolean readOnlyFlag) throws SQLException;
236
boolean isReadOnly(boolean useSessionStatus) throws SQLException;
237
void pingInternal(boolean checkForClosedConnection, int timeoutMillis) throws SQLException;
238
}
239
240
public class ConnectionImpl extends AbstractJdbcConnection implements JdbcConnection {
241
// Implementation of JdbcConnection interface
242
}
243
```
244
245
Usage:
246
247
```java
248
// Basic connection
249
Connection conn = DriverManager.getConnection(
250
"jdbc:mysql://localhost:3306/mydb?useSSL=false",
251
"user",
252
"password"
253
);
254
255
// Transaction management
256
conn.setAutoCommit(false);
257
try {
258
// Execute statements
259
Statement stmt = conn.createStatement();
260
stmt.executeUpdate("INSERT INTO users (name) VALUES ('Alice')");
261
stmt.executeUpdate("UPDATE accounts SET balance = balance - 100 WHERE user = 'Alice'");
262
263
conn.commit();
264
} catch (SQLException e) {
265
conn.rollback();
266
throw e;
267
}
268
269
// Connection validation
270
if (conn.isValid(5)) {
271
System.out.println("Connection is valid");
272
}
273
274
conn.close();
275
```
276
277
### Statement Execution
278
279
Standard Statement interface for executing SQL queries.
280
281
```java { .api }
282
package com.mysql.cj.jdbc;
283
284
public interface JdbcStatement extends java.sql.Statement {
285
// Query execution
286
ResultSet executeQuery(String sql) throws SQLException;
287
int executeUpdate(String sql) throws SQLException;
288
int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException;
289
int executeUpdate(String sql, int[] columnIndexes) throws SQLException;
290
int executeUpdate(String sql, String[] columnNames) throws SQLException;
291
boolean execute(String sql) throws SQLException;
292
boolean execute(String sql, int autoGeneratedKeys) throws SQLException;
293
boolean execute(String sql, int[] columnIndexes) throws SQLException;
294
boolean execute(String sql, String[] columnNames) throws SQLException;
295
296
// Result retrieval
297
ResultSet getResultSet() throws SQLException;
298
int getUpdateCount() throws SQLException;
299
boolean getMoreResults() throws SQLException;
300
boolean getMoreResults(int current) throws SQLException;
301
ResultSet getGeneratedKeys() throws SQLException;
302
303
// Batch operations
304
void addBatch(String sql) throws SQLException;
305
void clearBatch() throws SQLException;
306
int[] executeBatch() throws SQLException;
307
308
// Statement lifecycle
309
void close() throws SQLException;
310
boolean isClosed() throws SQLException;
311
void cancel() throws SQLException;
312
313
// Result set configuration
314
void setFetchDirection(int direction) throws SQLException;
315
int getFetchDirection() throws SQLException;
316
void setFetchSize(int rows) throws SQLException;
317
int getFetchSize() throws SQLException;
318
int getResultSetConcurrency() throws SQLException;
319
int getResultSetType() throws SQLException;
320
int getResultSetHoldability() throws SQLException;
321
322
// Query timeouts
323
void setQueryTimeout(int seconds) throws SQLException;
324
int getQueryTimeout() throws SQLException;
325
326
// Max rows and field size
327
void setMaxRows(int max) throws SQLException;
328
int getMaxRows() throws SQLException;
329
void setMaxFieldSize(int max) throws SQLException;
330
int getMaxFieldSize() throws SQLException;
331
332
// Warnings
333
SQLWarning getWarnings() throws SQLException;
334
void clearWarnings() throws SQLException;
335
336
// Cursor name
337
void setCursorName(String name) throws SQLException;
338
339
// Connection reference
340
Connection getConnection() throws SQLException;
341
342
// Poolability
343
void setPoolable(boolean poolable) throws SQLException;
344
boolean isPoolable() throws SQLException;
345
346
// Close on completion
347
void closeOnCompletion() throws SQLException;
348
boolean isCloseOnCompletion() throws SQLException;
349
350
// Escape processing
351
void setEscapeProcessing(boolean enable) throws SQLException;
352
353
// Large update counts
354
long getLargeUpdateCount() throws SQLException;
355
void setLargeMaxRows(long max) throws SQLException;
356
long getLargeMaxRows() throws SQLException;
357
long[] executeLargeBatch() throws SQLException;
358
long executeLargeUpdate(String sql) throws SQLException;
359
long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException;
360
long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException;
361
long executeLargeUpdate(String sql, String[] columnNames) throws SQLException;
362
363
// MySQL-specific methods
364
void enableStreamingResults() throws SQLException;
365
void disableStreamingResults() throws SQLException;
366
void setLocalInfileInputStream(InputStream stream);
367
InputStream getLocalInfileInputStream();
368
void setPingTarget(PingTarget pingTarget);
369
ExceptionInterceptor getExceptionInterceptor();
370
371
// Result set management
372
void notifyResultSetClose(ResultSetInternalMethods rs);
373
int getOpenResultSetCount();
374
void setHoldResultsOpenOverClose(boolean holdResultsOpenOverClose);
375
ResultSetInternalMethods getResultSetInternal();
376
377
// Query and attribute management
378
Query getQuery();
379
void setAttribute(String name, Object value);
380
void clearAttributes();
381
}
382
383
public class StatementImpl extends AbstractStatement implements JdbcStatement {
384
// Implementation of JdbcStatement interface
385
}
386
```
387
388
Usage:
389
390
```java
391
Statement stmt = conn.createStatement();
392
393
// Execute query
394
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
395
while (rs.next()) {
396
System.out.println(rs.getString("name"));
397
}
398
rs.close();
399
400
// Execute update
401
int rowsAffected = stmt.executeUpdate("UPDATE users SET active = 1 WHERE id = 5");
402
System.out.println("Rows updated: " + rowsAffected);
403
404
// Execute with auto-generated keys
405
stmt.executeUpdate(
406
"INSERT INTO users (name) VALUES ('Bob')",
407
Statement.RETURN_GENERATED_KEYS
408
);
409
ResultSet keys = stmt.getGeneratedKeys();
410
if (keys.next()) {
411
System.out.println("Generated ID: " + keys.getLong(1));
412
}
413
keys.close();
414
415
stmt.close();
416
```
417
418
### Prepared Statement
419
420
PreparedStatement interface for parameterized SQL execution with enhanced performance.
421
422
```java { .api }
423
package com.mysql.cj.jdbc;
424
425
public interface JdbcPreparedStatement extends java.sql.PreparedStatement, JdbcStatement {
426
// Execution
427
ResultSet executeQuery() throws SQLException;
428
int executeUpdate() throws SQLException;
429
boolean execute() throws SQLException;
430
long executeLargeUpdate() throws SQLException;
431
432
// Parameter setting - numeric types
433
void setBoolean(int parameterIndex, boolean x) throws SQLException;
434
void setByte(int parameterIndex, byte x) throws SQLException;
435
void setShort(int parameterIndex, short x) throws SQLException;
436
void setInt(int parameterIndex, int x) throws SQLException;
437
void setLong(int parameterIndex, long x) throws SQLException;
438
void setFloat(int parameterIndex, float x) throws SQLException;
439
void setDouble(int parameterIndex, double x) throws SQLException;
440
void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException;
441
442
// Parameter setting - string and character types
443
void setString(int parameterIndex, String x) throws SQLException;
444
void setNString(int parameterIndex, String value) throws SQLException;
445
void setBytes(int parameterIndex, byte[] x) throws SQLException;
446
447
// Parameter setting - date and time types
448
void setDate(int parameterIndex, Date x) throws SQLException;
449
void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException;
450
void setTime(int parameterIndex, Time x) throws SQLException;
451
void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException;
452
void setTimestamp(int parameterIndex, Timestamp x) throws SQLException;
453
void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException;
454
455
// Parameter setting - streams
456
void setAsciiStream(int parameterIndex, InputStream x) throws SQLException;
457
void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException;
458
void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException;
459
void setBinaryStream(int parameterIndex, InputStream x) throws SQLException;
460
void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException;
461
void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException;
462
void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException;
463
void setCharacterStream(int parameterIndex, Reader reader) throws SQLException;
464
void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException;
465
void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException;
466
void setNCharacterStream(int parameterIndex, Reader value) throws SQLException;
467
void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException;
468
469
// Parameter setting - LOBs
470
void setBlob(int parameterIndex, Blob x) throws SQLException;
471
void setBlob(int parameterIndex, InputStream inputStream) throws SQLException;
472
void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException;
473
void setClob(int parameterIndex, Clob x) throws SQLException;
474
void setClob(int parameterIndex, Reader reader) throws SQLException;
475
void setClob(int parameterIndex, Reader reader, long length) throws SQLException;
476
void setNClob(int parameterIndex, NClob value) throws SQLException;
477
void setNClob(int parameterIndex, Reader reader) throws SQLException;
478
void setNClob(int parameterIndex, Reader reader, long length) throws SQLException;
479
480
// Parameter setting - other types
481
void setObject(int parameterIndex, Object x) throws SQLException;
482
void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException;
483
void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)
484
throws SQLException;
485
void setNull(int parameterIndex, int sqlType) throws SQLException;
486
void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException;
487
void setRef(int parameterIndex, Ref x) throws SQLException;
488
void setArray(int parameterIndex, Array x) throws SQLException;
489
void setURL(int parameterIndex, URL x) throws SQLException;
490
void setRowId(int parameterIndex, RowId x) throws SQLException;
491
void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException;
492
493
// Parameter metadata
494
ParameterMetaData getParameterMetaData() throws SQLException;
495
496
// Batch operations
497
void addBatch() throws SQLException;
498
499
// Clear parameters
500
void clearParameters() throws SQLException;
501
502
// Metadata
503
ResultSetMetaData getMetaData() throws SQLException;
504
505
// MySQL-specific prepared statement methods
506
QueryBindings getQueryBindings();
507
byte[] getBytesRepresentation(int parameterIndex) throws SQLException;
508
QueryInfo getQueryInfo();
509
boolean isNull(int paramIndex) throws SQLException;
510
String getPreparedSql();
511
void setBytes(int parameterIndex, byte[] x, boolean escapeIfNeeded) throws SQLException;
512
void setBigInteger(int parameterIndex, BigInteger x) throws SQLException;
513
void setNull(int parameterIndex, MysqlType mysqlType) throws SQLException;
514
ParameterBindings getParameterBindings() throws SQLException;
515
}
516
517
public class ClientPreparedStatement extends StatementImpl implements JdbcPreparedStatement {
518
// Client-side prepared statement implementation
519
}
520
521
public class ServerPreparedStatement extends ClientPreparedStatement {
522
// Server-side prepared statement implementation
523
}
524
```
525
526
Usage:
527
528
```java
529
String sql = "SELECT * FROM users WHERE age > ? AND city = ?";
530
PreparedStatement pstmt = conn.prepareStatement(sql);
531
532
// Set parameters
533
pstmt.setInt(1, 18);
534
pstmt.setString(2, "New York");
535
536
// Execute query
537
ResultSet rs = pstmt.executeQuery();
538
while (rs.next()) {
539
System.out.println(rs.getString("name") + " - " + rs.getInt("age"));
540
}
541
rs.close();
542
543
// Reuse with different parameters
544
pstmt.setInt(1, 25);
545
pstmt.setString(2, "Boston");
546
rs = pstmt.executeQuery();
547
// Process results...
548
rs.close();
549
550
pstmt.close();
551
```
552
553
### Callable Statement
554
555
CallableStatement interface for executing stored procedures with input and output parameters.
556
557
```java { .api }
558
package com.mysql.cj.jdbc;
559
560
public class CallableStatement extends PreparedStatement implements java.sql.CallableStatement {
561
// Register output parameters
562
void registerOutParameter(int parameterIndex, int sqlType) throws SQLException;
563
void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException;
564
void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException;
565
void registerOutParameter(String parameterName, int sqlType) throws SQLException;
566
void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException;
567
void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException;
568
569
// Retrieve output parameters - by index
570
boolean wasNull() throws SQLException;
571
String getString(int parameterIndex) throws SQLException;
572
boolean getBoolean(int parameterIndex) throws SQLException;
573
byte getByte(int parameterIndex) throws SQLException;
574
short getShort(int parameterIndex) throws SQLException;
575
int getInt(int parameterIndex) throws SQLException;
576
long getLong(int parameterIndex) throws SQLException;
577
float getFloat(int parameterIndex) throws SQLException;
578
double getDouble(int parameterIndex) throws SQLException;
579
BigDecimal getBigDecimal(int parameterIndex) throws SQLException;
580
BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException;
581
byte[] getBytes(int parameterIndex) throws SQLException;
582
Date getDate(int parameterIndex) throws SQLException;
583
Date getDate(int parameterIndex, Calendar cal) throws SQLException;
584
Time getTime(int parameterIndex) throws SQLException;
585
Time getTime(int parameterIndex, Calendar cal) throws SQLException;
586
Timestamp getTimestamp(int parameterIndex) throws SQLException;
587
Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException;
588
Object getObject(int parameterIndex) throws SQLException;
589
Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException;
590
Ref getRef(int parameterIndex) throws SQLException;
591
Blob getBlob(int parameterIndex) throws SQLException;
592
Clob getClob(int parameterIndex) throws SQLException;
593
Array getArray(int parameterIndex) throws SQLException;
594
URL getURL(int parameterIndex) throws SQLException;
595
RowId getRowId(int parameterIndex) throws SQLException;
596
NClob getNClob(int parameterIndex) throws SQLException;
597
SQLXML getSQLXML(int parameterIndex) throws SQLException;
598
String getNString(int parameterIndex) throws SQLException;
599
Reader getCharacterStream(int parameterIndex) throws SQLException;
600
Reader getNCharacterStream(int parameterIndex) throws SQLException;
601
602
// Retrieve output parameters - by name
603
String getString(String parameterName) throws SQLException;
604
boolean getBoolean(String parameterName) throws SQLException;
605
byte getByte(String parameterName) throws SQLException;
606
short getShort(String parameterName) throws SQLException;
607
int getInt(String parameterName) throws SQLException;
608
long getLong(String parameterName) throws SQLException;
609
float getFloat(String parameterName) throws SQLException;
610
double getDouble(String parameterName) throws SQLException;
611
BigDecimal getBigDecimal(String parameterName) throws SQLException;
612
byte[] getBytes(String parameterName) throws SQLException;
613
Date getDate(String parameterName) throws SQLException;
614
Date getDate(String parameterName, Calendar cal) throws SQLException;
615
Time getTime(String parameterName) throws SQLException;
616
Time getTime(String parameterName, Calendar cal) throws SQLException;
617
Timestamp getTimestamp(String parameterName) throws SQLException;
618
Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException;
619
Object getObject(String parameterName) throws SQLException;
620
Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException;
621
Ref getRef(String parameterName) throws SQLException;
622
Blob getBlob(String parameterName) throws SQLException;
623
Clob getClob(String parameterName) throws SQLException;
624
Array getArray(String parameterName) throws SQLException;
625
URL getURL(String parameterName) throws SQLException;
626
RowId getRowId(String parameterName) throws SQLException;
627
NClob getNClob(String parameterName) throws SQLException;
628
SQLXML getSQLXML(String parameterName) throws SQLException;
629
String getNString(String parameterName) throws SQLException;
630
Reader getCharacterStream(String parameterName) throws SQLException;
631
Reader getNCharacterStream(String parameterName) throws SQLException;
632
633
// Set input parameters - by name
634
void setBoolean(String parameterName, boolean x) throws SQLException;
635
void setByte(String parameterName, byte x) throws SQLException;
636
void setShort(String parameterName, short x) throws SQLException;
637
void setInt(String parameterName, int x) throws SQLException;
638
void setLong(String parameterName, long x) throws SQLException;
639
void setFloat(String parameterName, float x) throws SQLException;
640
void setDouble(String parameterName, double x) throws SQLException;
641
void setBigDecimal(String parameterName, BigDecimal x) throws SQLException;
642
void setString(String parameterName, String x) throws SQLException;
643
void setBytes(String parameterName, byte[] x) throws SQLException;
644
void setDate(String parameterName, Date x) throws SQLException;
645
void setDate(String parameterName, Date x, Calendar cal) throws SQLException;
646
void setTime(String parameterName, Time x) throws SQLException;
647
void setTime(String parameterName, Time x, Calendar cal) throws SQLException;
648
void setTimestamp(String parameterName, Timestamp x) throws SQLException;
649
void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException;
650
void setAsciiStream(String parameterName, InputStream x) throws SQLException;
651
void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException;
652
void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException;
653
void setBinaryStream(String parameterName, InputStream x) throws SQLException;
654
void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException;
655
void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException;
656
void setCharacterStream(String parameterName, Reader reader) throws SQLException;
657
void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException;
658
void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException;
659
void setNCharacterStream(String parameterName, Reader value) throws SQLException;
660
void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException;
661
void setBlob(String parameterName, Blob x) throws SQLException;
662
void setBlob(String parameterName, InputStream inputStream) throws SQLException;
663
void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException;
664
void setClob(String parameterName, Clob x) throws SQLException;
665
void setClob(String parameterName, Reader reader) throws SQLException;
666
void setClob(String parameterName, Reader reader, long length) throws SQLException;
667
void setNClob(String parameterName, NClob value) throws SQLException;
668
void setNClob(String parameterName, Reader reader) throws SQLException;
669
void setNClob(String parameterName, Reader reader, long length) throws SQLException;
670
void setObject(String parameterName, Object x) throws SQLException;
671
void setObject(String parameterName, Object x, int targetSqlType) throws SQLException;
672
void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException;
673
void setNull(String parameterName, int sqlType) throws SQLException;
674
void setNull(String parameterName, int sqlType, String typeName) throws SQLException;
675
void setURL(String parameterName, URL val) throws SQLException;
676
void setRowId(String parameterName, RowId x) throws SQLException;
677
void setNString(String parameterName, String value) throws SQLException;
678
void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException;
679
}
680
```
681
682
Usage:
683
684
```java
685
// Call stored procedure with IN and OUT parameters
686
CallableStatement cstmt = conn.prepareCall("{call getUserStats(?, ?)}");
687
688
// Set IN parameter
689
cstmt.setInt(1, 123); // user_id
690
691
// Register OUT parameter
692
cstmt.registerOutParameter(2, Types.INTEGER); // total_orders
693
694
// Execute
695
cstmt.execute();
696
697
// Retrieve OUT parameter
698
int totalOrders = cstmt.getInt(2);
699
System.out.println("Total orders: " + totalOrders);
700
701
cstmt.close();
702
```
703
704
### Result Set Processing
705
706
ResultSet interface for navigating and retrieving query results.
707
708
```java { .api }
709
package com.mysql.cj.jdbc.result;
710
711
public interface ResultSetInternalMethods extends java.sql.ResultSet {
712
// Cursor navigation
713
boolean next() throws SQLException;
714
boolean previous() throws SQLException;
715
boolean first() throws SQLException;
716
boolean last() throws SQLException;
717
boolean absolute(int row) throws SQLException;
718
boolean relative(int rows) throws SQLException;
719
void beforeFirst() throws SQLException;
720
void afterLast() throws SQLException;
721
722
// Cursor position checking
723
boolean isBeforeFirst() throws SQLException;
724
boolean isAfterLast() throws SQLException;
725
boolean isFirst() throws SQLException;
726
boolean isLast() throws SQLException;
727
int getRow() throws SQLException;
728
729
// Data retrieval - by column index
730
String getString(int columnIndex) throws SQLException;
731
boolean getBoolean(int columnIndex) throws SQLException;
732
byte getByte(int columnIndex) throws SQLException;
733
short getShort(int columnIndex) throws SQLException;
734
int getInt(int columnIndex) throws SQLException;
735
long getLong(int columnIndex) throws SQLException;
736
float getFloat(int columnIndex) throws SQLException;
737
double getDouble(int columnIndex) throws SQLException;
738
BigDecimal getBigDecimal(int columnIndex) throws SQLException;
739
BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException;
740
byte[] getBytes(int columnIndex) throws SQLException;
741
Date getDate(int columnIndex) throws SQLException;
742
Date getDate(int columnIndex, Calendar cal) throws SQLException;
743
Time getTime(int columnIndex) throws SQLException;
744
Time getTime(int columnIndex, Calendar cal) throws SQLException;
745
Timestamp getTimestamp(int columnIndex) throws SQLException;
746
Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException;
747
Object getObject(int columnIndex) throws SQLException;
748
Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException;
749
InputStream getAsciiStream(int columnIndex) throws SQLException;
750
InputStream getBinaryStream(int columnIndex) throws SQLException;
751
InputStream getUnicodeStream(int columnIndex) throws SQLException;
752
Reader getCharacterStream(int columnIndex) throws SQLException;
753
Ref getRef(int columnIndex) throws SQLException;
754
Blob getBlob(int columnIndex) throws SQLException;
755
Clob getClob(int columnIndex) throws SQLException;
756
Array getArray(int columnIndex) throws SQLException;
757
URL getURL(int columnIndex) throws SQLException;
758
RowId getRowId(int columnIndex) throws SQLException;
759
NClob getNClob(int columnIndex) throws SQLException;
760
SQLXML getSQLXML(int columnIndex) throws SQLException;
761
String getNString(int columnIndex) throws SQLException;
762
Reader getNCharacterStream(int columnIndex) throws SQLException;
763
764
// Data retrieval - by column name
765
String getString(String columnLabel) throws SQLException;
766
boolean getBoolean(String columnLabel) throws SQLException;
767
byte getByte(String columnLabel) throws SQLException;
768
short getShort(String columnLabel) throws SQLException;
769
int getInt(String columnLabel) throws SQLException;
770
long getLong(String columnLabel) throws SQLException;
771
float getFloat(String columnLabel) throws SQLException;
772
double getDouble(String columnLabel) throws SQLException;
773
BigDecimal getBigDecimal(String columnLabel) throws SQLException;
774
BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException;
775
byte[] getBytes(String columnLabel) throws SQLException;
776
Date getDate(String columnLabel) throws SQLException;
777
Date getDate(String columnLabel, Calendar cal) throws SQLException;
778
Time getTime(String columnLabel) throws SQLException;
779
Time getTime(String columnLabel, Calendar cal) throws SQLException;
780
Timestamp getTimestamp(String columnLabel) throws SQLException;
781
Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException;
782
Object getObject(String columnLabel) throws SQLException;
783
Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException;
784
InputStream getAsciiStream(String columnLabel) throws SQLException;
785
InputStream getBinaryStream(String columnLabel) throws SQLException;
786
InputStream getUnicodeStream(String columnLabel) throws SQLException;
787
Reader getCharacterStream(String columnLabel) throws SQLException;
788
Ref getRef(String columnLabel) throws SQLException;
789
Blob getBlob(String columnLabel) throws SQLException;
790
Clob getClob(String columnLabel) throws SQLException;
791
Array getArray(String columnLabel) throws SQLException;
792
URL getURL(String columnLabel) throws SQLException;
793
RowId getRowId(String columnLabel) throws SQLException;
794
NClob getNClob(String columnLabel) throws SQLException;
795
SQLXML getSQLXML(String columnLabel) throws SQLException;
796
String getNString(String columnLabel) throws SQLException;
797
Reader getNCharacterStream(String columnLabel) throws SQLException;
798
799
// Null checking
800
boolean wasNull() throws SQLException;
801
802
// Result set metadata
803
ResultSetMetaData getMetaData() throws SQLException;
804
int findColumn(String columnLabel) throws SQLException;
805
806
// Warnings
807
SQLWarning getWarnings() throws SQLException;
808
void clearWarnings() throws SQLException;
809
810
// Cursor name
811
String getCursorName() throws SQLException;
812
813
// Statement reference
814
Statement getStatement() throws SQLException;
815
816
// Fetch configuration
817
void setFetchDirection(int direction) throws SQLException;
818
int getFetchDirection() throws SQLException;
819
void setFetchSize(int rows) throws SQLException;
820
int getFetchSize() throws SQLException;
821
822
// Result set type and concurrency
823
int getType() throws SQLException;
824
int getConcurrency() throws SQLException;
825
int getHoldability() throws SQLException;
826
827
// Lifecycle
828
void close() throws SQLException;
829
boolean isClosed() throws SQLException;
830
}
831
832
public class ResultSetImpl implements ResultSetInternalMethods {
833
// Standard result set implementation
834
}
835
836
public class UpdatableResultSet extends ResultSetImpl {
837
// Updatable result set with update methods
838
839
// Row updates - by column index
840
void updateNull(int columnIndex) throws SQLException;
841
void updateBoolean(int columnIndex, boolean x) throws SQLException;
842
void updateByte(int columnIndex, byte x) throws SQLException;
843
void updateShort(int columnIndex, short x) throws SQLException;
844
void updateInt(int columnIndex, int x) throws SQLException;
845
void updateLong(int columnIndex, long x) throws SQLException;
846
void updateFloat(int columnIndex, float x) throws SQLException;
847
void updateDouble(int columnIndex, double x) throws SQLException;
848
void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException;
849
void updateString(int columnIndex, String x) throws SQLException;
850
void updateBytes(int columnIndex, byte[] x) throws SQLException;
851
void updateDate(int columnIndex, Date x) throws SQLException;
852
void updateTime(int columnIndex, Time x) throws SQLException;
853
void updateTimestamp(int columnIndex, Timestamp x) throws SQLException;
854
void updateAsciiStream(int columnIndex, InputStream x) throws SQLException;
855
void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException;
856
void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException;
857
void updateBinaryStream(int columnIndex, InputStream x) throws SQLException;
858
void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException;
859
void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException;
860
void updateCharacterStream(int columnIndex, Reader x) throws SQLException;
861
void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException;
862
void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException;
863
void updateObject(int columnIndex, Object x) throws SQLException;
864
void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException;
865
void updateRef(int columnIndex, Ref x) throws SQLException;
866
void updateBlob(int columnIndex, Blob x) throws SQLException;
867
void updateBlob(int columnIndex, InputStream inputStream) throws SQLException;
868
void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException;
869
void updateClob(int columnIndex, Clob x) throws SQLException;
870
void updateClob(int columnIndex, Reader reader) throws SQLException;
871
void updateClob(int columnIndex, Reader reader, long length) throws SQLException;
872
void updateArray(int columnIndex, Array x) throws SQLException;
873
void updateRowId(int columnIndex, RowId x) throws SQLException;
874
void updateNString(int columnIndex, String nString) throws SQLException;
875
void updateNClob(int columnIndex, NClob nClob) throws SQLException;
876
void updateNClob(int columnIndex, Reader reader) throws SQLException;
877
void updateNClob(int columnIndex, Reader reader, long length) throws SQLException;
878
void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException;
879
void updateNCharacterStream(int columnIndex, Reader x) throws SQLException;
880
void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException;
881
882
// Row updates - by column name
883
void updateNull(String columnLabel) throws SQLException;
884
void updateBoolean(String columnLabel, boolean x) throws SQLException;
885
void updateByte(String columnLabel, byte x) throws SQLException;
886
void updateShort(String columnLabel, short x) throws SQLException;
887
void updateInt(String columnLabel, int x) throws SQLException;
888
void updateLong(String columnLabel, long x) throws SQLException;
889
void updateFloat(String columnLabel, float x) throws SQLException;
890
void updateDouble(String columnLabel, double x) throws SQLException;
891
void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException;
892
void updateString(String columnLabel, String x) throws SQLException;
893
void updateBytes(String columnLabel, byte[] x) throws SQLException;
894
void updateDate(String columnLabel, Date x) throws SQLException;
895
void updateTime(String columnLabel, Time x) throws SQLException;
896
void updateTimestamp(String columnLabel, Timestamp x) throws SQLException;
897
void updateAsciiStream(String columnLabel, InputStream x) throws SQLException;
898
void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException;
899
void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException;
900
void updateBinaryStream(String columnLabel, InputStream x) throws SQLException;
901
void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException;
902
void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException;
903
void updateCharacterStream(String columnLabel, Reader reader) throws SQLException;
904
void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException;
905
void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException;
906
void updateObject(String columnLabel, Object x) throws SQLException;
907
void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException;
908
void updateRef(String columnLabel, Ref x) throws SQLException;
909
void updateBlob(String columnLabel, Blob x) throws SQLException;
910
void updateBlob(String columnLabel, InputStream inputStream) throws SQLException;
911
void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException;
912
void updateClob(String columnLabel, Clob x) throws SQLException;
913
void updateClob(String columnLabel, Reader reader) throws SQLException;
914
void updateClob(String columnLabel, Reader reader, long length) throws SQLException;
915
void updateArray(String columnLabel, Array x) throws SQLException;
916
void updateRowId(String columnLabel, RowId x) throws SQLException;
917
void updateNString(String columnLabel, String nString) throws SQLException;
918
void updateNClob(String columnLabel, NClob nClob) throws SQLException;
919
void updateNClob(String columnLabel, Reader reader) throws SQLException;
920
void updateNClob(String columnLabel, Reader reader, long length) throws SQLException;
921
void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException;
922
void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException;
923
void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException;
924
925
// Row manipulation
926
void insertRow() throws SQLException;
927
void updateRow() throws SQLException;
928
void deleteRow() throws SQLException;
929
void refreshRow() throws SQLException;
930
void cancelRowUpdates() throws SQLException;
931
void moveToInsertRow() throws SQLException;
932
void moveToCurrentRow() throws SQLException;
933
boolean rowUpdated() throws SQLException;
934
boolean rowInserted() throws SQLException;
935
boolean rowDeleted() throws SQLException;
936
}
937
```
938
939
Usage:
940
941
```java
942
Statement stmt = conn.createStatement();
943
ResultSet rs = stmt.executeQuery("SELECT id, name, age FROM users");
944
945
while (rs.next()) {
946
int id = rs.getInt("id");
947
String name = rs.getString("name");
948
int age = rs.getInt(3); // by column index
949
950
System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
951
}
952
953
rs.close();
954
stmt.close();
955
```
956
957
### Result Set Metadata
958
959
Metadata about result set columns including names, types, and properties.
960
961
```java { .api }
962
package com.mysql.cj.jdbc.result;
963
964
public class ResultSetMetaData implements java.sql.ResultSetMetaData {
965
// Column count
966
int getColumnCount() throws SQLException;
967
968
// Column naming
969
String getColumnName(int column) throws SQLException;
970
String getColumnLabel(int column) throws SQLException;
971
972
// Table information
973
String getTableName(int column) throws SQLException;
974
String getSchemaName(int column) throws SQLException;
975
String getCatalogName(int column) throws SQLException;
976
977
// Type information
978
int getColumnType(int column) throws SQLException;
979
String getColumnTypeName(int column) throws SQLException;
980
String getColumnClassName(int column) throws SQLException;
981
982
// Size and precision
983
int getColumnDisplaySize(int column) throws SQLException;
984
int getPrecision(int column) throws SQLException;
985
int getScale(int column) throws SQLException;
986
987
// Column properties
988
boolean isAutoIncrement(int column) throws SQLException;
989
boolean isCaseSensitive(int column) throws SQLException;
990
boolean isCurrency(int column) throws SQLException;
991
int isNullable(int column) throws SQLException;
992
boolean isSigned(int column) throws SQLException;
993
boolean isReadOnly(int column) throws SQLException;
994
boolean isWritable(int column) throws SQLException;
995
boolean isDefinitelyWritable(int column) throws SQLException;
996
boolean isSearchable(int column) throws SQLException;
997
}
998
999
public interface CachedResultSetMetaData extends ResultSetMetaData {
1000
// Cached metadata interface
1001
}
1002
1003
public class CachedResultSetMetaDataImpl implements CachedResultSetMetaData {
1004
// Cached metadata implementation
1005
}
1006
```
1007
1008
Usage:
1009
1010
```java
1011
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
1012
ResultSetMetaData meta = rs.getMetaData();
1013
1014
int columnCount = meta.getColumnCount();
1015
System.out.println("Columns: " + columnCount);
1016
1017
for (int i = 1; i <= columnCount; i++) {
1018
System.out.println("Column " + i + ":");
1019
System.out.println(" Name: " + meta.getColumnName(i));
1020
System.out.println(" Type: " + meta.getColumnTypeName(i));
1021
System.out.println(" Size: " + meta.getColumnDisplaySize(i));
1022
System.out.println(" Nullable: " + (meta.isNullable(i) == ResultSetMetaData.columnNullable));
1023
}
1024
```
1025
1026
### Database Metadata
1027
1028
Comprehensive metadata about the database capabilities, schemas, tables, and columns.
1029
1030
```java { .api }
1031
package com.mysql.cj.jdbc;
1032
1033
public class DatabaseMetaData implements java.sql.DatabaseMetaData {
1034
// Database product information
1035
String getDatabaseProductName() throws SQLException;
1036
String getDatabaseProductVersion() throws SQLException;
1037
int getDatabaseMajorVersion() throws SQLException;
1038
int getDatabaseMinorVersion() throws SQLException;
1039
1040
// Driver information
1041
String getDriverName() throws SQLException;
1042
String getDriverVersion() throws SQLException;
1043
int getDriverMajorVersion();
1044
int getDriverMinorVersion();
1045
1046
// JDBC version
1047
int getJDBCMajorVersion() throws SQLException;
1048
int getJDBCMinorVersion() throws SQLException;
1049
1050
// SQL support
1051
boolean supportsTransactions() throws SQLException;
1052
boolean supportsStoredProcedures() throws SQLException;
1053
boolean supportsOuterJoins() throws SQLException;
1054
boolean supportsFullOuterJoins() throws SQLException;
1055
boolean supportsLimitedOuterJoins() throws SQLException;
1056
boolean supportsSubqueriesInComparisons() throws SQLException;
1057
boolean supportsSubqueriesInExists() throws SQLException;
1058
boolean supportsSubqueriesInIns() throws SQLException;
1059
boolean supportsSubqueriesInQuantifieds() throws SQLException;
1060
boolean supportsCorrelatedSubqueries() throws SQLException;
1061
boolean supportsUnion() throws SQLException;
1062
boolean supportsUnionAll() throws SQLException;
1063
1064
// Transaction support
1065
boolean supportsMultipleTransactions() throws SQLException;
1066
boolean supportsTransactionIsolationLevel(int level) throws SQLException;
1067
int getDefaultTransactionIsolation() throws SQLException;
1068
boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException;
1069
boolean supportsDataManipulationTransactionsOnly() throws SQLException;
1070
boolean dataDefinitionCausesTransactionCommit() throws SQLException;
1071
boolean dataDefinitionIgnoredInTransactions() throws SQLException;
1072
1073
// Result set support
1074
boolean supportsResultSetType(int type) throws SQLException;
1075
boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException;
1076
boolean ownUpdatesAreVisible(int type) throws SQLException;
1077
boolean ownDeletesAreVisible(int type) throws SQLException;
1078
boolean ownInsertsAreVisible(int type) throws SQLException;
1079
boolean othersUpdatesAreVisible(int type) throws SQLException;
1080
boolean othersDeletesAreVisible(int type) throws SQLException;
1081
boolean othersInsertsAreVisible(int type) throws SQLException;
1082
boolean updatesAreDetected(int type) throws SQLException;
1083
boolean deletesAreDetected(int type) throws SQLException;
1084
boolean insertsAreDetected(int type) throws SQLException;
1085
1086
// Batch updates
1087
boolean supportsBatchUpdates() throws SQLException;
1088
1089
// Savepoints
1090
boolean supportsSavepoints() throws SQLException;
1091
1092
// Named parameters
1093
boolean supportsNamedParameters() throws SQLException;
1094
1095
// Multiple open results
1096
boolean supportsMultipleOpenResults() throws SQLException;
1097
1098
// Schema information
1099
ResultSet getCatalogs() throws SQLException;
1100
ResultSet getSchemas() throws SQLException;
1101
ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException;
1102
1103
// Table information
1104
ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern,
1105
String[] types) throws SQLException;
1106
ResultSet getTableTypes() throws SQLException;
1107
1108
// Column information
1109
ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern,
1110
String columnNamePattern) throws SQLException;
1111
1112
// Primary key information
1113
ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException;
1114
1115
// Foreign key information
1116
ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException;
1117
ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException;
1118
ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable,
1119
String foreignCatalog, String foreignSchema, String foreignTable)
1120
throws SQLException;
1121
1122
// Index information
1123
ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique,
1124
boolean approximate) throws SQLException;
1125
1126
// Procedure information
1127
ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
1128
throws SQLException;
1129
ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern,
1130
String columnNamePattern) throws SQLException;
1131
1132
// Function information
1133
ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern)
1134
throws SQLException;
1135
ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern,
1136
String columnNamePattern) throws SQLException;
1137
1138
// Type information
1139
ResultSet getTypeInfo() throws SQLException;
1140
ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types)
1141
throws SQLException;
1142
1143
// Connection reference
1144
Connection getConnection() throws SQLException;
1145
1146
// User information
1147
String getUserName() throws SQLException;
1148
1149
// URL information
1150
String getURL() throws SQLException;
1151
1152
// Nullability information
1153
boolean supportsNonNullableColumns() throws SQLException;
1154
int getMaxConnections() throws SQLException;
1155
int getMaxStatements() throws SQLException;
1156
1157
// SQL keywords
1158
String getSQLKeywords() throws SQLException;
1159
String getNumericFunctions() throws SQLException;
1160
String getStringFunctions() throws SQLException;
1161
String getSystemFunctions() throws SQLException;
1162
String getTimeDateFunctions() throws SQLException;
1163
1164
// Search string escape
1165
String getSearchStringEscape() throws SQLException;
1166
1167
// Extra name characters
1168
String getExtraNameCharacters() throws SQLException;
1169
1170
// Identifier quote string
1171
String getIdentifierQuoteString() throws SQLException;
1172
1173
// Case sensitivity
1174
boolean supportsMixedCaseIdentifiers() throws SQLException;
1175
boolean storesUpperCaseIdentifiers() throws SQLException;
1176
boolean storesLowerCaseIdentifiers() throws SQLException;
1177
boolean storesMixedCaseIdentifiers() throws SQLException;
1178
boolean supportsMixedCaseQuotedIdentifiers() throws SQLException;
1179
boolean storesUpperCaseQuotedIdentifiers() throws SQLException;
1180
boolean storesLowerCaseQuotedIdentifiers() throws SQLException;
1181
boolean storesMixedCaseQuotedIdentifiers() throws SQLException;
1182
}
1183
1184
public class DatabaseMetaDataUsingInfoSchema extends DatabaseMetaData {
1185
// Implementation using INFORMATION_SCHEMA tables
1186
}
1187
```
1188
1189
Usage:
1190
1191
```java
1192
DatabaseMetaData meta = conn.getMetaData();
1193
1194
System.out.println("Database: " + meta.getDatabaseProductName() +
1195
" " + meta.getDatabaseProductVersion());
1196
System.out.println("Driver: " + meta.getDriverName() +
1197
" " + meta.getDriverVersion());
1198
1199
// List all tables
1200
ResultSet tables = meta.getTables(null, null, "%", new String[]{"TABLE"});
1201
while (tables.next()) {
1202
String tableName = tables.getString("TABLE_NAME");
1203
System.out.println("Table: " + tableName);
1204
1205
// Get columns for this table
1206
ResultSet columns = meta.getColumns(null, null, tableName, "%");
1207
while (columns.next()) {
1208
String columnName = columns.getString("COLUMN_NAME");
1209
String columnType = columns.getString("TYPE_NAME");
1210
System.out.println(" Column: " + columnName + " (" + columnType + ")");
1211
}
1212
columns.close();
1213
}
1214
tables.close();
1215
```
1216
1217
### DataSource
1218
1219
DataSource implementation for obtaining connections in managed environments.
1220
1221
```java { .api }
1222
package com.mysql.cj.jdbc;
1223
1224
public class MysqlDataSource implements javax.sql.DataSource, java.io.Serializable {
1225
// Connection retrieval
1226
public Connection getConnection() throws SQLException;
1227
public Connection getConnection(String username, String password) throws SQLException;
1228
1229
// Configuration properties
1230
public void setURL(String url);
1231
public String getURL();
1232
public void setUrl(String url); // Alternative setter
1233
public String getUrl(); // Alternative getter
1234
1235
public void setUser(String user);
1236
public String getUser();
1237
public void setPassword(String password);
1238
1239
public void setServerName(String serverName);
1240
public String getServerName();
1241
public void setPort(int port);
1242
public int getPort();
1243
public void setPortNumber(int port); // Alternative setter
1244
public int getPortNumber(); // Alternative getter
1245
1246
public void setDatabaseName(String databaseName);
1247
public String getDatabaseName();
1248
1249
public void setServerTimezone(String serverTimezone);
1250
public String getServerTimezone();
1251
1252
public void setUseSSL(boolean useSSL);
1253
public boolean getUseSSL();
1254
1255
public void setRequireSSL(boolean requireSSL);
1256
public boolean getRequireSSL();
1257
1258
public void setVerifyServerCertificate(boolean verifyServerCertificate);
1259
public boolean getVerifyServerCertificate();
1260
1261
public void setCharacterEncoding(String characterEncoding);
1262
public String getCharacterEncoding();
1263
1264
public void setAutoReconnect(boolean autoReconnect);
1265
public boolean getAutoReconnect();
1266
1267
public void setUseUnicode(boolean useUnicode);
1268
public boolean getUseUnicode();
1269
1270
public void setProfileSQL(boolean profileSQL);
1271
public boolean getProfileSQL();
1272
1273
public void setLogger(String logger);
1274
public String getLogger();
1275
1276
public void setUseInformationSchema(boolean useInformationSchema);
1277
public boolean getUseInformationSchema();
1278
1279
public void setZeroDateTimeBehavior(String zeroDateTimeBehavior);
1280
public String getZeroDateTimeBehavior();
1281
1282
public void setCachePrepStmts(boolean cachePrepStmts);
1283
public boolean getCachePrepStmts();
1284
1285
public void setPrepStmtCacheSize(int prepStmtCacheSize);
1286
public int getPrepStmtCacheSize();
1287
1288
public void setPrepStmtCacheSqlLimit(int prepStmtCacheSqlLimit);
1289
public int getPrepStmtCacheSqlLimit();
1290
1291
public void setRewriteBatchedStatements(boolean rewriteBatchedStatements);
1292
public boolean getRewriteBatchedStatements();
1293
1294
// Timeout settings
1295
public void setConnectTimeout(int connectTimeout);
1296
public int getConnectTimeout();
1297
1298
public void setSocketTimeout(int socketTimeout);
1299
public int getSocketTimeout();
1300
1301
// Logging
1302
public PrintWriter getLogWriter() throws SQLException;
1303
public void setLogWriter(PrintWriter out) throws SQLException;
1304
1305
public void setLoginTimeout(int seconds) throws SQLException;
1306
public int getLoginTimeout() throws SQLException;
1307
1308
// Parent logger
1309
public Logger getParentLogger() throws SQLFeatureNotSupportedException;
1310
}
1311
1312
public class MysqlDataSourceFactory implements ObjectFactory {
1313
// Factory for JNDI lookup
1314
public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable<?, ?> env)
1315
throws Exception;
1316
}
1317
```
1318
1319
Usage:
1320
1321
```java
1322
// Configure DataSource
1323
MysqlDataSource ds = new MysqlDataSource();
1324
ds.setURL("jdbc:mysql://localhost:3306/mydb");
1325
ds.setUser("root");
1326
ds.setPassword("password");
1327
1328
// Or configure via properties
1329
ds.setServerName("localhost");
1330
ds.setPort(3306);
1331
ds.setDatabaseName("mydb");
1332
ds.setUser("root");
1333
ds.setPassword("password");
1334
1335
// Performance optimizations
1336
ds.setCachePrepStmts(true);
1337
ds.setPrepStmtCacheSize(250);
1338
ds.setPrepStmtCacheSqlLimit(2048);
1339
ds.setRewriteBatchedStatements(true);
1340
1341
// Get connection
1342
Connection conn = ds.getConnection();
1343
// Use connection...
1344
conn.close();
1345
```
1346
1347
### LOB Support
1348
1349
Support for Binary Large Objects (BLOB) and Character Large Objects (CLOB).
1350
1351
```java { .api }
1352
package com.mysql.cj.jdbc;
1353
1354
public class Blob implements java.sql.Blob {
1355
// Constructor
1356
public Blob(byte[] data);
1357
1358
// Length
1359
long length() throws SQLException;
1360
1361
// Retrieve data
1362
byte[] getBytes(long pos, int length) throws SQLException;
1363
InputStream getBinaryStream() throws SQLException;
1364
InputStream getBinaryStream(long pos, long length) throws SQLException;
1365
1366
// Find position
1367
long position(byte[] pattern, long start) throws SQLException;
1368
long position(java.sql.Blob pattern, long start) throws SQLException;
1369
1370
// Modify data
1371
int setBytes(long pos, byte[] bytes) throws SQLException;
1372
int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException;
1373
OutputStream setBinaryStream(long pos) throws SQLException;
1374
void truncate(long len) throws SQLException;
1375
1376
// Lifecycle
1377
void free() throws SQLException;
1378
}
1379
1380
public class Clob implements java.sql.Clob {
1381
// Constructor
1382
public Clob(String charData);
1383
1384
// Length
1385
long length() throws SQLException;
1386
1387
// Retrieve data
1388
String getSubString(long pos, int length) throws SQLException;
1389
Reader getCharacterStream() throws SQLException;
1390
Reader getCharacterStream(long pos, long length) throws SQLException;
1391
InputStream getAsciiStream() throws SQLException;
1392
1393
// Find position
1394
long position(String searchstr, long start) throws SQLException;
1395
long position(java.sql.Clob searchstr, long start) throws SQLException;
1396
1397
// Modify data
1398
int setString(long pos, String str) throws SQLException;
1399
int setString(long pos, String str, int offset, int len) throws SQLException;
1400
OutputStream setAsciiStream(long pos) throws SQLException;
1401
Writer setCharacterStream(long pos) throws SQLException;
1402
void truncate(long len) throws SQLException;
1403
1404
// Lifecycle
1405
void free() throws SQLException;
1406
}
1407
1408
public class NClob extends Clob implements java.sql.NClob {
1409
// National Character Large Object
1410
public NClob(String charData);
1411
}
1412
1413
public class MysqlSQLXML implements java.sql.SQLXML {
1414
// XML data support
1415
void free() throws SQLException;
1416
InputStream getBinaryStream() throws SQLException;
1417
OutputStream setBinaryStream() throws SQLException;
1418
Reader getCharacterStream() throws SQLException;
1419
Writer setCharacterStream() throws SQLException;
1420
String getString() throws SQLException;
1421
void setString(String value) throws SQLException;
1422
<T extends javax.xml.transform.Source> T getSource(Class<T> sourceClass) throws SQLException;
1423
<T extends javax.xml.transform.Result> T setResult(Class<T> resultClass) throws SQLException;
1424
}
1425
```
1426
1427
Usage:
1428
1429
```java
1430
// Writing a BLOB
1431
PreparedStatement pstmt = conn.prepareStatement(
1432
"INSERT INTO documents (name, content) VALUES (?, ?)"
1433
);
1434
pstmt.setString(1, "document.pdf");
1435
1436
byte[] fileData = Files.readAllBytes(Paths.get("document.pdf"));
1437
Blob blob = new Blob(fileData);
1438
pstmt.setBlob(2, blob);
1439
pstmt.executeUpdate();
1440
1441
// Reading a BLOB
1442
ResultSet rs = stmt.executeQuery("SELECT content FROM documents WHERE id = 1");
1443
if (rs.next()) {
1444
Blob docBlob = rs.getBlob("content");
1445
byte[] data = docBlob.getBytes(1, (int) docBlob.length());
1446
Files.write(Paths.get("output.pdf"), data);
1447
docBlob.free();
1448
}
1449
1450
// Writing a CLOB
1451
Clob clob = new Clob("Large text content...");
1452
pstmt.setClob(2, clob);
1453
pstmt.executeUpdate();
1454
1455
// Reading a CLOB
1456
Clob textClob = rs.getClob("description");
1457
String text = textClob.getSubString(1, (int) textClob.length());
1458
```
1459
1460
### Savepoints
1461
1462
Transaction savepoints for partial rollback within a transaction.
1463
1464
```java { .api }
1465
package com.mysql.cj.jdbc;
1466
1467
public class MysqlSavepoint implements java.sql.Savepoint {
1468
// Named savepoint
1469
public MysqlSavepoint(String name);
1470
1471
// Unnamed savepoint
1472
public MysqlSavepoint();
1473
1474
// Savepoint identification
1475
int getSavepointId() throws SQLException;
1476
String getSavepointName() throws SQLException;
1477
}
1478
```
1479
1480
Usage:
1481
1482
```java
1483
conn.setAutoCommit(false);
1484
1485
try {
1486
stmt.executeUpdate("INSERT INTO accounts (name, balance) VALUES ('Alice', 1000)");
1487
1488
// Create savepoint
1489
Savepoint sp1 = conn.setSavepoint("savepoint1");
1490
1491
stmt.executeUpdate("UPDATE accounts SET balance = balance - 100 WHERE name = 'Alice'");
1492
1493
// Something goes wrong, rollback to savepoint
1494
if (someCondition) {
1495
conn.rollback(sp1);
1496
}
1497
1498
stmt.executeUpdate("UPDATE accounts SET balance = balance + 50 WHERE name = 'Alice'");
1499
1500
conn.commit();
1501
} catch (SQLException e) {
1502
conn.rollback();
1503
throw e;
1504
}
1505
```
1506
1507
### Parameter Metadata
1508
1509
Metadata about prepared statement parameters.
1510
1511
```java { .api }
1512
package com.mysql.cj.jdbc;
1513
1514
public class MysqlParameterMetadata implements java.sql.ParameterMetaData {
1515
// Constructor
1516
public MysqlParameterMetadata(int parameterCount);
1517
1518
// Parameter count
1519
int getParameterCount() throws SQLException;
1520
1521
// Parameter type information
1522
int getParameterType(int param) throws SQLException;
1523
String getParameterTypeName(int param) throws SQLException;
1524
String getParameterClassName(int param) throws SQLException;
1525
1526
// Parameter mode
1527
int getParameterMode(int param) throws SQLException;
1528
1529
// Nullability
1530
int isNullable(int param) throws SQLException;
1531
1532
// Sign
1533
boolean isSigned(int param) throws SQLException;
1534
1535
// Precision and scale
1536
int getPrecision(int param) throws SQLException;
1537
int getScale(int param) throws SQLException;
1538
}
1539
```
1540
1541
Usage:
1542
1543
```java
1544
PreparedStatement pstmt = conn.prepareStatement(
1545
"SELECT * FROM users WHERE age > ? AND city = ?"
1546
);
1547
1548
ParameterMetaData paramMeta = pstmt.getParameterMetaData();
1549
int paramCount = paramMeta.getParameterCount();
1550
System.out.println("Parameter count: " + paramCount);
1551
1552
for (int i = 1; i <= paramCount; i++) {
1553
System.out.println("Parameter " + i + ":");
1554
System.out.println(" Type: " + paramMeta.getParameterTypeName(i));
1555
System.out.println(" Class: " + paramMeta.getParameterClassName(i));
1556
System.out.println(" Mode: " + paramMeta.getParameterMode(i));
1557
}
1558
```
1559
1560
### Client Info Provider
1561
1562
Mechanism for storing and retrieving client information in the database.
1563
1564
```java { .api }
1565
package com.mysql.cj.jdbc;
1566
1567
public interface ClientInfoProvider {
1568
void initialize(Connection conn, Properties configurationProps) throws SQLException;
1569
void destroy() throws SQLException;
1570
1571
Properties getClientInfo(Connection conn) throws SQLException;
1572
String getClientInfo(Connection conn, String name) throws SQLException;
1573
1574
void setClientInfo(Connection conn, Properties properties) throws SQLClientInfoException;
1575
void setClientInfo(Connection conn, String name, String value) throws SQLClientInfoException;
1576
}
1577
1578
public class ClientInfoProviderSP implements ClientInfoProvider {
1579
// Stored procedure-based implementation
1580
public void initialize(Connection conn, Properties configurationProps) throws SQLException;
1581
public void destroy() throws SQLException;
1582
public Properties getClientInfo(Connection conn) throws SQLException;
1583
public String getClientInfo(Connection conn, String name) throws SQLException;
1584
public void setClientInfo(Connection conn, Properties properties) throws SQLClientInfoException;
1585
public void setClientInfo(Connection conn, String name, String value) throws SQLClientInfoException;
1586
}
1587
1588
public class CommentClientInfoProvider implements ClientInfoProvider {
1589
// Comment-based implementation (prepends client info as SQL comments)
1590
public void initialize(Connection conn, Properties configurationProps) throws SQLException;
1591
public void destroy() throws SQLException;
1592
public Properties getClientInfo(Connection conn) throws SQLException;
1593
public String getClientInfo(Connection conn, String name) throws SQLException;
1594
public void setClientInfo(Connection conn, Properties properties) throws SQLClientInfoException;
1595
public void setClientInfo(Connection conn, String name, String value) throws SQLClientInfoException;
1596
}
1597
```
1598
1599
Usage:
1600
1601
```java
1602
Connection conn = DriverManager.getConnection(url, props);
1603
1604
// Set client info
1605
conn.setClientInfo("ApplicationName", "MyApp");
1606
conn.setClientInfo("ClientUser", "john.doe");
1607
1608
// Get client info
1609
String appName = conn.getClientInfo("ApplicationName");
1610
Properties allClientInfo = conn.getClientInfo();
1611
```
1612
1613
### Connection Close Options
1614
1615
Options for controlling connection close behavior.
1616
1617
```java { .api }
1618
package com.mysql.cj.jdbc;
1619
1620
public enum CloseOption {
1621
IMPLICIT, // Close operation initiated internally by a clean up routine
1622
FORCED, // A forced, hard close
1623
ROLLBACK, // Allow rollback during the close operation
1624
PROPAGATE, // Allow propagating the close operation to dependents and owner objects
1625
NO_CACHE; // Does not allow caching the closing object
1626
1627
public boolean in(CloseOption... options);
1628
public boolean notIn(CloseOption... options);
1629
}
1630
```
1631
1632
These options are used by advanced connection management methods like `doClose(Throwable cause, CloseOption... options)` for fine-grained control over connection cleanup behavior.
1633