Advertisement
Sylv3rWolf

HikariConfig

Oct 23rd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. @Bean
  2.     public DataSource ds()  {
  3.         HikariConfig hc = new HikariConfig();
  4.         hc.setJdbcUrl("jdbc:mysql://localhost(lub adres serwera/nazwa)");
  5.         hc.addDataSourceProperty("serverName", "nazwa_serwera");
  6.         hc.addDataSourceProperty("databaseName", "nazwa_bazy");
  7.         hc.addDataSourceProperty("user", "nazwa_uzytkownika");
  8.         hc.addDataSourceProperty("password", "haslo");
  9.         hc.setDriverClassName("com.mysql.jdbc.Driver");
  10.         //te nizej sa zwykle niepotrzebne, dotyczą struktury samej bazy i pamięci
  11.         hc.addDataSourceProperty("cachePrepStmts", "true");
  12.         hc.addDataSourceProperty("prepStmtCacheSize", "250");
  13.         hc.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
  14.         hc.addDataSourceProperty("useUnicode", "yes");
  15.         hc.addDataSourceProperty("characterEncoding", "utf8");      
  16.         return new HikariDataSource(hc);
  17.     }
  18.  
  19.  
  20. przykładowe dependencje do springa
  21.         <dependency>
  22.             <groupId>mysql</groupId>
  23.             <artifactId>mysql-connector-java</artifactId>
  24.             <version>5.1.39</version>
  25.         </dependency>
  26.         <dependency>
  27.             <groupId>com.zaxxer</groupId>
  28.             <artifactId>HikariCP</artifactId>
  29.             <version>2.6.1</version>
  30.             <scope>compile</scope>
  31.         </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement