Setting up a database - Sponge-RPG-dev/NT-RPG GitHub Wiki
All your database configuration is in a file database.properties. This file is located in a config/nt-core folder and generated during the first plugin startup.
The file looks like this:
(Every line which starts with #
character is a comment)
(Following example is for postgresql)
### Hibernate setup`
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.hbm2ddl.auto=create
hibernate.show_sql=false
### Hikari Connection pool setup
#Hikari is a connection pool, the library comes with sponge
#Do not change provider_class unless you know what are you doing.
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=5
hibernate.hikari.maximumPoolSize=10
hibernate.hikari.idleTimeout=30000
### PostgreSQL datasource *
#This is a datasource class, each database vendor has its own
#Do not forget to install jdbc driver(!) for your database
hibernate.hikari.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
hibernate.hikari.username=username
hibernate.hikari.password=password
### PGSimpleDataSource *(!!)
hibernate.hikari.dataSource.serverName=localhost
hibernate.hikari.dataSource.portNumber=5432
hibernate.hikari.dataSource.databaseName=dbname
*
- Names of properties depend on a choosen database. Properties names will be different (more or less) for different types of databases
-
dialect - Represents which dialect will hibernate use.
-
hbm2.dll.auto: during the first startup make sure its value is create or create, then change its value to update or validate
- validate: validate the schema, makes no changes to the database.
- update: update the schema.
- create: creates the schema, destroying previous data.
- create-drop: drop the schema at the end of the session.
Table of most common dialects:
RDBMS | Dialect |
---|---|
DB2 | org.hibernate.dialect.DB2Dialect |
DB2 AS/400 | org.hibernate.dialect.DB2400Dialect |
DB2 OS390 | org.hibernate.dialect.DB2390Dialect |
PostgreSQL | org.hibernate.dialect.PostgreSQLDialect |
MySQL | org.hibernate.dialect.MySQLDialect |
MySQL with InnoDB | org.hibernate.dialect.MySQLInnoDBDialect |
MySQL with MyISAM | org.hibernate.dialect.MySQLMyISAMDialect |
Oracle (any version) | org.hibernate.dialect.OracleDialect |
Oracle 9i/10g | org.hibernate.dialect.Oracle9Dialect |
Sybase | org.hibernate.dialect.SybaseDialect |
Sybase Anywhere | org.hibernate.dialect.SybaseAnywhereDialect |
Microsoft SQL Server | org.hibernate.dialect.SQLServerDialect |
SAP DB | org.hibernate.dialect.SAPDBDialect |
Informix | org.hibernate.dialect.InformixDialect |
HypersonicSQL (also works for h2) | org.hibernate.dialect.HSQLDialect |
Ingres | org.hibernate.dialect.IngresDialect |
Progress | org.hibernate.dialect.ProgressDialect |
Mckoi SQL | org.hibernate.dialect.MckoiDialect |
Interbase | org.hibernate.dialect.InterbaseDialect |
Pointbase | org.hibernate.dialect.PointbaseDialect |
FrontBase | org.hibernate.dialect.FrontbaseDialect |
Firebird | org.hibernate.dialect.FirebirdDialect |
H2 | org.hibernate.dialect.H2Dialect |
If you would like to use a self-contained databse do not try to use litesql, use H2 instead
Example of database properties for mysql:
### Hibernate setup
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=create
hibernate.show_sql=false
### Hikari Connection pool setup
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=3
hibernate.hikari.maximumPoolSize=10
hibernate.hikari.idleTimeout=30000
### PostgreSQL datasource *
hibernate.hikari.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
### PGSimpleDataSource *
hibernate.hikari.dataSource.url=jdbc:mysql://ip:port/database
hibernate.hikari.dataSource.user=
hibernate.hikari.dataSource.password=
Example of database properties for H2:
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=5
hibernate.hikari.maximumPoolSize=10
hibernate.hikari.idleTimeout=30000
hibernate.hikari.dataSourceClassName=org.h2.jdbcx.JdbcDataSource
hibernate.hikari.username=sa
hibernate.hikari.password=
hibernate.hikari.dataSource.url=jdbc:h2:~/h2
FAQ:
java.lang.RuntimeException: java.lang.ClassNotFoundException: <datasource.class.name>
- Jdbc driver is not installed.
- You wrote wrong classpath to the datasource class.
How do i install a JDBC driver, its not bundled thogether with plugin
- If you are using SpongeForge simply put the library into your mods folder. FML will load the library during its startup.
- If you are using SpongeVanilla put the library into config/nt-core folder. Plugin will load the library during sponge startup.