Category : jdbc

Order Database connection pool is used in java. If the deployment is careless, the typical connection pool may be full. abnormal org.postgresql.util.PSQLException: FATAL: sorry, too many clients already at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:408) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:181) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64) at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:144) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29) at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21) at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31) at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:410) at org.postgresql.Driver.connect(Driver.java:280) at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:732) at ..

Read more

Order Tomcat jdbc provides an interceptor like SlowQueryReport, which can be used to record slow query sql that exceeds a threshold. In addition to the jmx access provided by SlowQueryReportJmx, how can ordinary web access relevant statistical information? Get QueryStats SlowQueryReport provides a static statistical map, so it can be called directly @RequestMapping(value = “/slow-sql”,method ..

Read more

Order This article mainly introduces the RowMapper of spring jdbc. RowMapper spring-jdbc-4.3.10.RELEASE-sources.jar! /org/springframework/jdbc/core/RowMapper.java public interface RowMapper<T> { /** * Implementations must implement this method to map each row of data * in the ResultSet. This method should not call {@code next()} on * the ResultSet; it is only supposed to map values of the current ..

Read more

Order This article mainly talks about the generation class of querydsl. maven <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-sql</artifactId> <version>4.1.4</version> </dependency> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>4.1.4</version> </dependency> <dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-jpa</artifactId> <version>4.1.4</version> </dependency> plugin <plugin> <groupId>com.querydsl</groupId> <artifactId>querydsl-maven-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>process</goal> </goals> <configuration> <outputDirectory>target/generated-sources</outputDirectory> <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor> </configuration> </execution> </executions> </plugin> Generate q class mvn compile However, because it is generated in ..

Read more

Order This article mainly introduces the setting of socket timeout in jdbc. Jdbtimeout class There are mainly the following categories transaction timeout The setting is the execution time of a transaction, which may contain multiple statement. statement timeout(It is also equivalent to result set fetch timeout.) The setting is the timeout period for the execution ..

Read more

Order This article mainly studies the fetchSize of jdbc statement. fetchSize Taking postgres jdbc driver as an example, this is mainly because postgres jdbc driver has open source code and its naming is relatively standard. Looking at oracle jdbc before, due to the lack of source code, a lot of variable names such as var1 ..

Read more

Order This article mainly introduces queryTimeout of pg jdbc statement and next method of resultSet. Instance program @Test public void testReadTimeout() throws SQLException { Connection connection = dataSource.getConnection(); //https://jdbc.postgresql.org/documentation/head/query.html connection.setAutoCommit(false); //NOTE 为了设置fetchSize,必须设置为false String sql = “select * from demo_table”; PreparedStatement pstmt; try { pstmt = (PreparedStatement)connection.prepareStatement(sql); pstmt.setQueryTimeout(1); //NOTE 设置Statement执行完成的超时时间,前提是socket的timeout比这个大 pstmt.setFetchSize(5000); //NOTE 这样设置为了模拟query timeout的异常 System.out.println(“ps.getQueryTimeout():” + ..

Read more

Order This article mainly introduces queryTimeout of mysql jdbc statement and next method of resultSet. executeQuery() mysql-connector-java-5.1.43-sources.jar! /com/mysql/jdbc/PreparedStatement.java /** * A Prepared SQL query is executed and its ResultSet is returned * * @return a ResultSet that contains the data produced by the query – never * null * * @exception SQLException * if a ..

Read more

Order This article mainly analyzes the maxRows parameter of pg jdbc statement. Statement.setMaxRows void setMaxRows(int max) throws SQLException Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number. If the limit is exceeded, the excess rows are silently dropped. Parameters: max ..

Read more

Order This article mainly studies the default parameters of tomcat jdbc pool and poolSweeper. Tomcat jdbc pool parameter default initialSize = 10(Default value) maxActive=100(Default value) maxIdle=100(Default value) minIdle=10(Default value) maxWait=30000(Default value) validationQueryTimeout=-1(Default value) testOnBorrow=false(Default value) testOnReturn=false(Default value) testWhileIdel=false(Default value) timeBetweenEvictionRunsMillis=5000(Default value) minEvictableIdleTimeMillis=60000(Default value) accessToUnderlyingConnectionAllowed=true(Default value) removeAbandoned=false(Default value) removeAbandonedTimeout=60(Default value) logAbandoned=false(Default value) validationInterval=3000(Default value) testOnConnect=false(Default value) ..

Read more

Order This article mainly studies the use of jdbc’s batch and jpa’s batch settings. batch Statement’s batch operation can perform insert or update operations in batches to improve operation performance, especially when large amounts of data are inserted or updated. Use way @Test public void testSqlInjectSafeBatch(){ String sql = “insert into employee (name, city, phone) ..

Read more

Order This article mainly studies the realization of jpa’s batch operation. Save method SessionImpl.persist hibernate-core-5.0.12.Final-sources.jar! /org/hibernate/internal/SessionImpl.java @Override public void persist(String entityName, Object object) throws HibernateException { firePersist( new PersistEvent( entityName, object, this ) ); } private void firePersist(PersistEvent event) { errorIfClosed(); checkTransactionSynchStatus(); checkNoUnresolvedActionsBeforeOperation(); for ( PersistEventListener listener : listeners( EventType.PERSIST ) ) { listener.onPersist( event ..

Read more