title: Java connect to SQL Anywhere 17
body: <p>I'm working on a school project and I have to connect to a database done in SQL anywhere 17 and I keep getting the flowing error: </p>
  
  <blockquote>
    <p>No suitable driver found for jdbc:sqlanywhere:Tds:localhost:2638?eng="DBNAME".</p>
  </blockquote>
  
  <p>Any help is welcome.</p>
  
  <p>Here is the code for the class doing the connection.</p>
  
  <pre><code>package model;
  
  import java.sql.*;
  
  public class DBConnection {
  
      public class ConnectionHandler {
          ResultSet r;
          Statement s;
          String returnStatus;
      }
  
      private String db, user, passwd;
      private String dbUrl;
      private Connection conn;
  
      public DBConnection(String db, String user, String passwd, Object openserver, String databasepath) {
          this.db = db;
          this.user = user;
          this.passwd = passwd;
  
          dbUrl = "jdbc:sqlanywhere:Tds:localhost:2638?eng=" + db;
  
          try {
              conn = DriverManager.getConnection(dbUrl, user, passwd);
              conn.setAutoCommit(false);
          } catch (Exception e) {
              System.out.println(e);
              Boolean openServer = (Boolean) openserver;
              if (openServer.booleanValue())
                  try {
                      String engcommand = "dbeng12 " + databasepath + db + ".db";
                      Runtime.getRuntime().exec(engcommand);
                      long t0, t1;
                      t0 = System.currentTimeMillis();
                      do {
                          t1 = System.currentTimeMillis();
                      } while (t1 - t0 &lt; 5000);
                      conn = DriverManager.getConnection(dbUrl, user, passwd);
                      conn.setAutoCommit(false);
                  } catch (Exception ex) {
                      System.out.println("Unable to start server. " + ex);
                  }
          }
      }
  
      public void updateStatement(String sql, ConnectionHandler ch) {
          Integer result = new Integer(0);
          String message = null;
  
          if (sql.trim().substring(0, 1).equalsIgnoreCase("U"))
              message = "Number of rows updated: ";
          else if (sql.trim().substring(0, 1).equalsIgnoreCase("I"))
              message = "Number of rows inserted: ";
          else
              message = " ";
  
          try {
              ch.s = conn.createStatement();
              result = new Integer(ch.s.executeUpdate(sql));
              ch.returnStatus = message + result;
          } catch (Exception e) {
              System.out.println("Unable to execute the insert/update/delete statement. " + e);
              ch.returnStatus = "Error:" + e.toString();
          }
      }
  
      public void returnResultSetSelectStatement(String sql, int resultsetType, ConnectionHandler ch) {
          ch.r = null;
          try {
              if (resultsetType == 1)
                  ch.s = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
              else
                  ch.s = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
              ch.r = ch.s.executeQuery(sql);
  
          } catch (Exception e) {
              ch.returnStatus = e.toString();
              System.out.println("Unable to execute the returnSelectStatement. " + e);
          }
      }
  
  }
  </code></pre>