Connect SQL Server via GWT


  • Eclipse 3.5
  • Google Web Toolkit Eclipse plug-in 2.0.4
  • SEQL Server 2005

Google plug-in uses Jetty [1] as web (Servlet) container. The key is Jetty configuration.

Step 1: create jetty configuration xml file

Create file named “jetty-web.xml” under /war/WEB-INF/

The content is:

<?xml version="1.0" encoding="UTF-8"?>
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
    <New id="DSTest" class="">
            <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
                <Set name="User">sa</Set>
                <Set name="Password">123456</Set>
                <Set name="DatabaseName">Repository</Set>
                <Set name="ServerName">localhost</Set>
                <Set name="PortNumber">1433</Set>

Step 2: set up JDBC driver

Download jtds JDBC driver [2] and copy the jar file into /war/WEB-INF/lib/ and your project class path. I firstly use the official Microsoft driver but did no work.

To connect other database, please refer to [3].

Step 3: code snippet

The code to access database should be server side. To get a JDBC connection, the code is:

    public static Connection getSQLServerConnection() {
        try {
            if (con == null || con.isClosed()) {
                Context context = new InitialContext();
                DataSource dataSource = (DataSource) context
                con = dataSource.getConnection();

        } catch (NamingException e) {

        } catch (SQLException e) {
        return con;

The rest code is same as normal JDBC programming.

Step 4: set up jetty jar

Down jetty-naming and jetty-plus jar file from [4] and copy to /war/WEB-INF/lib/ and your project class path.


[1] Jetty:

[2] Jtds:

[3] Jetty data source:

[4] Jetty jar: