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:


3 thoughts on “Connect SQL Server via GWT

  1. I’m using: Eclipse Helios, Windows 7 GWT-plugin.
    In my configuration javax-naming is not supported.
    Which files I have to import?

  2. My environement : Windows 7, Eclipse Helios, GWT plugin. In my environement:
    import javax.naming.InitialContext;
    import javax.naming.*;
    is not supported by GWT. What I can do?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s