Örnek
Şöyle yaparız
jdbc:mysql://localhost:3306/jdbc_demo
Örnek
user ve password için Şöyle yaparızjdbc:mysql://localhost:3306/mydatabase?user=myusername&password=mypassword
Örnek - Multi-Host Connections
Failover için şöyle yaparız
jdbc:mysql://192.168.29.20:3306,192.168.29.20:6306/adv
Açıklaması şöyle
The host list in the connection URL comprises of two types of hosts, the primary and the secondary. When starting a new connection, the driver always tries to connect to the primary host first and, if required, fails over to the secondary hosts on the list sequentially when communication problems are experienced. Even if the initial connection to the primary host fails and the driver gets connected to a secondary host, the primary host never loses its special status: for example, it can be configured with an access mode distinct from those of the secondary hosts, and it can be put on a higher priority when a host is to be picked during a failover process.
autoReconnect
Açıklaması şöyle
autoReconnect=true in the connection string, which makes the connection to auto recover.
Şöyle yaparız.
"jdbc:mysql://localhost:yourPortNumber/yourDatabaseName?autoReconnect=true";
logger
Şöyle yaparız. Burada logger olarak SLF4J kullanılmak isteniyor.
jdbc:mysql://myexample.com:3306/pets?logger=Slf4JLogger&explainSlowQueries=true
serverTimezone
Örnek
Şöyle yaparız
jdbc:mysql://... &useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
sql_mode
SQL içindeki ANSI çift tırnakları kabul etmek için şöyle yaparız
jdbc:mysql://localhost:3306/db?sessionVariables=sql_mode=ANSI_QUOTES
Böylece şöyle SQL'ler işlenebilir.
SELECT * FROM "account" WHERE "deleted" IS NULL ORDER BY "account_name"
socketTimeout
Açıklaması şöyle. Yani
- connectTimeout veri tabanına bağlanmak için ne kadar beklemek istediğimizi belirtir.
- socketTimeout okuma, yazma gibi işlemlerde sokette ne kadar sürede bir veri olması istediğimizi belirtir.
connectTimeoutDefault value: 0Unit: millisecondConfigure the connection timeout time, through the connect(SocketAddress endpoint, int timeout) method of the Socket object to configuresocketTimeoutDefault value: 0Unit: msConfigure the timeout time of the socket, and configure it through the setSoTimeout(int timeout) method of the Socket object
Şöyle yaparız. Burada her ikisi için de 1 dakika kullanılıyor
jdbc:mysql://xxx.xx.xxx.xxx:3306/database?connectTimeout=60000&socketTimeout=60000
socketTimeout çıktısı şöyle
Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:171) at java.net.SocketInputStream.read(SocketInputStream.java:141) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3008) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3469)
useSSL
Şöyle yaparız. Burada bağlantıda SSL kullanılmaz
"jdbc:mysql://localhost:yourPortNumber/yourDatabaseName?autoReconnect=true&useSSL=false";
useUnicode
Şöyle yaparız
"jdbc:mysql://127.0.0.1:3306/mydb?
useUnicode=true&
characterEncoding=UTF-8&
useServerPrepStmts=false&
rewriteBatchedStatements=true"
Açıklaması şöyle
By default the MySQL driver does not support batching because of how it handles queries. To enable batching we have to tell it to rewrite queries by adding ?rewriteBatchedStatements=true to your JDBC URL.
useCursorFetch
Açıklaması şöyle
In MySQL, the useCursorFetch parameter is a JDBC driver-specific option that can be used to enable or disable cursor-based fetching for result sets. Cursor-based fetching allows fetching rows from the result set in smaller chunks (cursors) instead of loading the entire result set into memory at once.When useCursorFetch is set to true, the MySQL JDBC driver uses server-side cursors to fetch rows in chunks. This can be beneficial when dealing with large result sets as it reduces memory consumption and can improve performance.Here's an example of how to enable useCursorFetch in a MySQL JDBC connection string:String jdbcUrl = "jdbc:mysql://your_host:your_port/your_database?useCursorFetch=true";In the JDBC connection URL, appending ?useCursorFetch=true at the end enables the cursor-based fetching mode for the MySQL JDBC driver.
Hiç yorum yok:
Yorum Gönder