Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
<html>
<head>
<title>SQL Server | Ebean ORM</title>
<meta name="layout" content="_layout2/base-docs.html"/>
<meta name="bread1" content="Database platforms" href="/docs/database"/>
<meta name="bread2" content="SQL Server" href="/docs/database/sqlserver"/>
<#assign n0_docs="active">
<#assign n1_platforms="active">
<#assign n2_sqlserver="active">
</head>
<body>
<h2>SQL Server</h2>
<p>
With SQL Server we have to decide if we are going to use the <code>sqlserver17</code> or the default older one.
</p>
<h3 id="sqlserver17">sqlserver17</h3>
<p>
To setup to use sqlserver17 we should set the <code>databasePlatformName</code> to sqlserver17 at either the
<code>ebean.databasePlatformName</code>> level or at <code>ebean.test.sqlserver.databasePlatformName</code>> level.
</p>
<pre content="yml">
ebean:
databasePlatformName: sqlserver17 ## only using sql server
test:
platform: sqlserver # h2, postgres, mysql, oracle, sqlserver
ddlMode: dropCreate # none | dropCreate | migrations
dbName: test
sqlserver:
#collation: SQL_Latin1_General_CP1_CS_AS ## use an explicit collation
#collation: default ## use the sql server default
</pre>
<p>
When testing against multiple database platforms put <code>databasePlatformName: sqlserver17</code>
under <code>sqlserver</code> like the example below:
</p>
<pre content="yml">
ebean:
test:
platform: sqlserver # h2, postgres, mysql, oracle, sqlserver
ddlMode: dropCreate # none | dropCreate | migrations | create
dbName: test
sqlserver:
databasePlatformName: sqlserver17 ## put here when testing multiple platforms
#collation: SQL_Latin1_General_CP1_CS_AS ## use an explicit collation
#collation: default ## use the sql server default
</pre>
<p>
The above will use the following defaults:
</p>
<table class="compact w100">
<tr><th>username:</th><td>{databaseName}</td></tr>
<tr><th>password:</th><td>SqlS3rv#r</td></tr>
<tr><th>port:</th><td>1433</td></tr>
<tr><th>url:</th><td>jdbc:sqlserver://localhost:{port};databaseName={databaseName}</td></tr>
<tr><th>driver:</th><td>com.microsoft.sqlserver.jdbc.SQLServerDriver</td></tr>
<tr><th>image:</th><td>microsoft/mssql-server-linux:{version}</td></tr>
</table>
<h2 id="ebean-sqlserver">ebean-sqlserver dependency</h2>
<p>
We can use the <code>io.ebean:ebean-sqlserver</code> dependency rather than <code>io.ebean:ebean</code> if we want to only
bring in the SqlServer specific platform code. Depending on <code>io.ebean:ebean</code> will bring in all platforms.
</p>
<h2 id="starting">Docker container</h2>
<p>
We can programmatically start a docker container version of SqlServer.
</p>
<p>
The below uses <code>ebean-test-docker</code> dependency which already comes with <code>ebean-test</code>.
If we do not have a dependency on <code>ebean-test</code> then add <code>io.ebean:ebean-test-docker:5.0</code>
as a dependency.
</p>
<pre content="java">
package main;
import io.ebean.docker.commands.SqlServerContainer;
public class Main {
public static void main(String[] args) {
SqlServerContainer container = SqlServerContainer.newBuilder("2019-CU15-ubuntu-20.04")
.dbName("my_app")
.collation("SQL_Latin1_General_CP1_CS_AS")
// .containerName("ut_sqlserver")
// .port(1433)
.build();
container.start();
}
}
</pre>
<@next_edit "Oracle" "/docs/database/oracle" "/docs/database/sqlserver/index.html"/>
</body>
</html>