LibrayCompiler error

padvou

Active Member
Licensed User
Longtime User
LibraryCompiler error

After downloading this
I run it and get an error: Additional libraries folder must be set in the IDE.
What do I need to do?

Moreover, is there some newbie tutorial about this tool?
 
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
After downloading this
I run it and get an error: Additional libraries folder must be set in the IDE.
What do I need to do?

Moreover, is there some newbie tutorial about this tool?

Hi padvou,
Please attached files.
 
Last edited:
Upvote 0

padvou

Active Member
Licensed User
Longtime User
I try to recompile the attached code from here
so that it points to the new jtds library which is jtds-1.3.1.jar

I managed to recompile it with this tool but I when I run the application I get an java.lang.ClassNotFoundException

Could someone assist me please?
 

Attachments

  • mssqljava.txt
    5.1 KB · Views: 208
Upvote 0

padvou

Active Member
Licensed User
Longtime User
Anyone please?
I also tried the procedure with eclipse, but I only end up with an xml file and no jar..:BangHead::BangHead::BangHead:
 
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
What is this error:
B4X:
 package com.test clashes with class of same name

Hi padvou,
I think that you should a new create emulator as a new name which could help you. Please,make surely,you get SLC version 1.00.
 
Last edited:
Upvote 0

padvou

Active Member
Licensed User
Longtime User
You should update this line to reference the correct jar file.

Yes, I've already tried that.
The code is attached which comes from this post

This is the link to the jtds-1.3.1.jar file.
Could you assist me with this please?
 

Attachments

  • mssqljava.txt
    5.1 KB · Views: 217
Last edited:
Upvote 0

padvou

Active Member
Licensed User
Longtime User
This is the error message:
B4X:
java.lang.ClassNotFoundException
As for the threading thing, I 've send it to a background thread using code at runtime (CallSubExtended). I guess it's working because I run it using SDK>11
I attach the files I created using SimpleLibraryCompiler which produce the error.
 

Attachments

  • mssql.zip
    3.2 KB · Views: 188
Upvote 0

padvou

Active Member
Licensed User
Longtime User
This is the long version of the error:
B4X:
java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

Here's the codes for jtds-1.2.5 jdbc driver:
B4X:
package net.sourceforge.jtds.jdbc;

import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

public class Driver
  implements java.sql.Driver
{
  private static String driverPrefix = "jdbc:jtds:";
  static final int MAJOR_VERSION = 1;
  static final int MINOR_VERSION = 2;
  static final String MISC_VERSION = ".5";
  public static final boolean JDBC3 = "1.4".compareTo(System.getProperty("java.specification.version")) <= 0;
  public static final int TDS42 = 1;
  public static final int TDS50 = 2;
  public static final int TDS70 = 3;
  public static final int TDS80 = 4;
  public static final int TDS81 = 5;
  public static final int SQLSERVER = 1;
  public static final int SYBASE = 2;
  public static final String APPNAME = "prop.appname";
  public static final String BATCHSIZE = "prop.batchsize";
  public static final String BINDADDRESS = "prop.bindaddress";
  public static final String BUFFERDIR = "prop.bufferdir";
  public static final String BUFFERMAXMEMORY = "prop.buffermaxmemory";
  public static final String BUFFERMINPACKETS = "prop.bufferminpackets";
  public static final String CACHEMETA = "prop.cachemetadata";
  public static final String CHARSET = "prop.charset";
  public static final String DATABASENAME = "prop.databasename";
  public static final String DOMAIN = "prop.domain";
  public static final String INSTANCE = "prop.instance";
  public static final String LANGUAGE = "prop.language";
  public static final String LASTUPDATECOUNT = "prop.lastupdatecount";
  public static final String LOBBUFFER = "prop.lobbuffer";
  public static final String LOGFILE = "prop.logfile";
  public static final String LOGINTIMEOUT = "prop.logintimeout";
  public static final String MACADDRESS = "prop.macaddress";
  public static final String MAXSTATEMENTS = "prop.maxstatements";
  public static final String NAMEDPIPE = "prop.namedpipe";
  public static final String PACKETSIZE = "prop.packetsize";
  public static final String PASSWORD = "prop.password";
  public static final String PORTNUMBER = "prop.portnumber";
  public static final String PREPARESQL = "prop.preparesql";
  public static final String PROGNAME = "prop.progname";
  public static final String SERVERNAME = "prop.servername";
  public static final String SERVERTYPE = "prop.servertype";
  public static final String SOTIMEOUT = "prop.sotimeout";
  public static final String SOKEEPALIVE = "prop.sokeepalive";
  public static final String PROCESSID = "prop.processid";
  public static final String SSL = "prop.ssl";
  public static final String TCPNODELAY = "prop.tcpnodelay";
  public static final String TDS = "prop.tds";
  public static final String USECURSORS = "prop.usecursors";
  public static final String USEJCIFS = "prop.usejcifs";
  public static final String USENTLMV2 = "prop.usentlmv2";
  public static final String USELOBS = "prop.uselobs";
  public static final String USER = "prop.user";
  public static final String SENDSTRINGPARAMETERSASUNICODE = "prop.useunicode";
  public static final String WSID = "prop.wsid";
  public static final String XAEMULATION = "prop.xaemulation";

  public int getMajorVersion()
  {
    return 1;
  }

  public int getMinorVersion() {
    return 2;
  }

  public static final String getVersion()
  {
    return "1.2" + (".5" == null ? "" : ".5");
  }

  public String toString()
  {
    return "jTDS " + getVersion();
  }

  public boolean jdbcCompliant() {
    return false;
  }

  public boolean acceptsURL(String url) throws SQLException {
    if (url == null) {
      return false;
    }

    return url.toLowerCase().startsWith(driverPrefix);
  }

  public Connection connect(String url, Properties info) throws SQLException
  {
    if ((url == null) || (!url.toLowerCase().startsWith(driverPrefix))) {
      return null;
    }

    Properties props = setupConnectProperties(url, info);

    if (JDBC3) {
      return new ConnectionJDBC3(url, props);
    }

    return new ConnectionJDBC2(url, props);
  }

  public DriverPropertyInfo[] getPropertyInfo(String url, Properties props)
    throws SQLException
  {
    Properties parsedProps = parseURL(url, props == null ? new Properties() : props);

    if (parsedProps == null) {
      throw new SQLException(Messages.get("error.driver.badurl", url), "08001");
    }

    parsedProps = DefaultProperties.addDefaultProperties(parsedProps);

    Map propertyMap = new HashMap();
    Map descriptionMap = new HashMap();
    Messages.loadDriverProperties(propertyMap, descriptionMap);

    Map choicesMap = createChoicesMap();
    Map requiredTrueMap = createRequiredTrueMap();

    DriverPropertyInfo[] dpi = new DriverPropertyInfo[propertyMap.size()];
    Iterator iterator = propertyMap.entrySet().iterator();
    for (int i = 0; iterator.hasNext(); i++)
    {
      Map.Entry entry = (Map.Entry)iterator.next();
      String key = (String)entry.getKey();
      String name = (String)entry.getValue();

      DriverPropertyInfo info = new DriverPropertyInfo(name, parsedProps.getProperty(name));
      info.description = ((String)descriptionMap.get(key));
      info.required = requiredTrueMap.containsKey(name);

      if (choicesMap.containsKey(name)) {
        info.choices = ((String[])choicesMap.get(name));
      }

      dpi[i] = info;
    }

    return dpi;
  }

  private Properties setupConnectProperties(String url, Properties info)
    throws SQLException
  {
    Properties props = parseURL(url, info);

    if (props == null) {
      throw new SQLException(Messages.get("error.driver.badurl", url), "08001");
    }

    if (props.getProperty(Messages.get("prop.logintimeout")) == null) {
      props.setProperty(Messages.get("prop.logintimeout"), Integer.toString(DriverManager.getLoginTimeout()));
    }

    props = DefaultProperties.addDefaultProperties(props);
    return props;
  }

  private static Map createChoicesMap()
  {
    HashMap choicesMap = new HashMap();

    String[] booleanChoices = { "true", "false" };
    choicesMap.put(Messages.get("prop.cachemetadata"), booleanChoices);
    choicesMap.put(Messages.get("prop.lastupdatecount"), booleanChoices);
    choicesMap.put(Messages.get("prop.namedpipe"), booleanChoices);
    choicesMap.put(Messages.get("prop.tcpnodelay"), booleanChoices);
    choicesMap.put(Messages.get("prop.useunicode"), booleanChoices);
    choicesMap.put(Messages.get("prop.usecursors"), booleanChoices);
    choicesMap.put(Messages.get("prop.uselobs"), booleanChoices);
    choicesMap.put(Messages.get("prop.xaemulation"), booleanChoices);

    String[] prepareSqlChoices = { String.valueOf(0), String.valueOf(1), String.valueOf(2), String.valueOf(3) };

    choicesMap.put(Messages.get("prop.preparesql"), prepareSqlChoices);

    String[] serverTypeChoices = { String.valueOf(1), String.valueOf(2) };

    choicesMap.put(Messages.get("prop.servertype"), serverTypeChoices);

    String[] tdsChoices = { "4.2", "5.0", "7.0", "8.0" };

    choicesMap.put(Messages.get("prop.tds"), tdsChoices);

    String[] sslChoices = { "off", "request", "require", "authenticate" };

    choicesMap.put(Messages.get("prop.ssl"), sslChoices);

    return choicesMap;
  }

  private static Map createRequiredTrueMap()
  {
    HashMap requiredTrueMap = new HashMap();
    requiredTrueMap.put(Messages.get("prop.servername"), null);
    requiredTrueMap.put(Messages.get("prop.servertype"), null);
    return requiredTrueMap;
  }

  private static Properties parseURL(String url, Properties info)
  {
    Properties props = new Properties();

    for (Enumeration e = info.propertyNames(); e.hasMoreElements(); ) {
      String key = (String)e.nextElement();
      String value = info.getProperty(key);

      if (value != null) {
        props.setProperty(key.toUpperCase(), value);
      }
    }

    StringBuffer token = new StringBuffer(16);
    int pos = 0;

    pos = nextToken(url, pos, token);

    if (!"jdbc".equalsIgnoreCase(token.toString())) {
      return null;
    }

    pos = nextToken(url, pos, token);

    if (!"jtds".equalsIgnoreCase(token.toString())) {
      return null;
    }

    pos = nextToken(url, pos, token);
    String type = token.toString().toLowerCase();

    Integer serverType = DefaultProperties.getServerType(type);
    if (serverType == null) {
      return null;
    }
    props.setProperty(Messages.get("prop.servertype"), String.valueOf(serverType));

    pos = nextToken(url, pos, token);

    if (token.length() > 0) {
      return null;
    }

    pos = nextToken(url, pos, token);
    String host = token.toString();

    if (host.length() == 0) {
      host = props.getProperty(Messages.get("prop.servername"));
      if ((host == null) || (host.length() == 0)) {
        return null;
      }
    }

    props.setProperty(Messages.get("prop.servername"), host);

    if ((url.charAt(pos - 1) == ':') && (pos < url.length())) {
      pos = nextToken(url, pos, token);
      try
      {
        int port = Integer.parseInt(token.toString());
        props.setProperty(Messages.get("prop.portnumber"), Integer.toString(port));
      } catch (NumberFormatException e) {
        return null;
      }
    }

    if ((url.charAt(pos - 1) == '/') && (pos < url.length())) {
      pos = nextToken(url, pos, token);
      props.setProperty(Messages.get("prop.databasename"), token.toString());
    }

    while ((url.charAt(pos - 1) == ';') && (pos < url.length())) {
      pos = nextToken(url, pos, token);
      String tmp = token.toString();
      int index = tmp.indexOf('=');

      if ((index > 0) && (index < tmp.length() - 1))
        props.setProperty(tmp.substring(0, index).toUpperCase(), tmp.substring(index + 1));
      else {
        props.setProperty(tmp.toUpperCase(), "");
      }
    }

    return props;
  }

  private static int nextToken(String url, int pos, StringBuffer token)
  {
    token.setLength(0);

    while (pos < url.length()) {
      char ch = url.charAt(pos++);

      if ((ch == ':') || (ch == ';'))
      {
        break;
      }
      if (ch == '/') {
        if ((pos >= url.length()) || (url.charAt(pos) != '/')) break;
        pos++; break;
      }

      token.append(ch);
    }

    return pos;
  }

  public static void main(String[] args) {
    System.out.println("jTDS " + getVersion());
  }

  static
  {
    try
    {
      DriverManager.registerDriver(new Driver());
    }
    catch (SQLException e)
    {
    }
  }
}

and for the 1.3.1 version:
B4X:
package net.sourceforge.jtds.jdbc;

import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;

public class Driver
  implements java.sql.Driver
{
  private static String driverPrefix = "jdbc:jtds:";
  static final int MAJOR_VERSION = 1;
  static final int MINOR_VERSION = 3;
  static final String MISC_VERSION = ".1";
  public static final int TDS42 = 1;
  public static final int TDS50 = 2;
  public static final int TDS70 = 3;
  public static final int TDS80 = 4;
  public static final int TDS81 = 5;
  public static final int TDS90 = 6;
  public static final int SQLSERVER = 1;
  public static final int SYBASE = 2;
  public static final String APPNAME = "prop.appname";
  public static final String AUTOCOMMIT = "prop.autocommit";
  public static final String BATCHSIZE = "prop.batchsize";
  public static final String BINDADDRESS = "prop.bindaddress";
  public static final String BUFFERDIR = "prop.bufferdir";
  public static final String BUFFERMAXMEMORY = "prop.buffermaxmemory";
  public static final String BUFFERMINPACKETS = "prop.bufferminpackets";
  public static final String CACHEMETA = "prop.cachemetadata";
  public static final String CHARSET = "prop.charset";
  public static final String DATABASENAME = "prop.databasename";
  public static final String DOMAIN = "prop.domain";
  public static final String INSTANCE = "prop.instance";
  public static final String LANGUAGE = "prop.language";
  public static final String LASTUPDATECOUNT = "prop.lastupdatecount";
  public static final String LOBBUFFER = "prop.lobbuffer";
  public static final String LOGFILE = "prop.logfile";
  public static final String LOGINTIMEOUT = "prop.logintimeout";
  public static final String MACADDRESS = "prop.macaddress";
  public static final String MAXSTATEMENTS = "prop.maxstatements";
  public static final String NAMEDPIPE = "prop.namedpipe";
  public static final String PACKETSIZE = "prop.packetsize";
  public static final String PASSWORD = "prop.password";
  public static final String PORTNUMBER = "prop.portnumber";
  public static final String PREPARESQL = "prop.preparesql";
  public static final String PROGNAME = "prop.progname";
  public static final String SERVERNAME = "prop.servername";
  public static final String SERVERTYPE = "prop.servertype";
  public static final String SOTIMEOUT = "prop.sotimeout";
  public static final String SOKEEPALIVE = "prop.sokeepalive";
  public static final String PROCESSID = "prop.processid";
  public static final String SSL = "prop.ssl";
  public static final String TCPNODELAY = "prop.tcpnodelay";
  public static final String TDS = "prop.tds";
  public static final String USECURSORS = "prop.usecursors";
  public static final String USEJCIFS = "prop.usejcifs";
  public static final String USENTLMV2 = "prop.usentlmv2";
  public static final String USEKERBEROS = "prop.usekerberos";
  public static final String USELOBS = "prop.uselobs";
  public static final String USER = "prop.user";
  public static final String SENDSTRINGPARAMETERSASUNICODE = "prop.useunicode";
  public static final String WSID = "prop.wsid";
  public static final String XAEMULATION = "prop.xaemulation";

  public int getMajorVersion()
  {
    return 1;
  }

  public int getMinorVersion() {
    return 3;
  }

  public static final String getVersion()
  {
    return new StringBuilder().append("1.3").append(".1" == null ? "" : ".1").toString();
  }

  public String toString()
  {
    return new StringBuilder().append("jTDS ").append(getVersion()).toString();
  }

  public boolean jdbcCompliant() {
    return false;
  }

  public boolean acceptsURL(String url) throws SQLException {
    if (url == null) {
      return false;
    }

    return url.toLowerCase().startsWith(driverPrefix);
  }

  public Connection connect(String url, Properties info) throws SQLException
  {
    if ((url == null) || (!url.toLowerCase().startsWith(driverPrefix))) {
      return null;
    }

    Properties props = setupConnectProperties(url, info);

    return new JtdsConnection(url, props);
  }

  public DriverPropertyInfo[] getPropertyInfo(String url, Properties props)
    throws SQLException
  {
    Properties parsedProps = parseURL(url, props == null ? new Properties() : props);

    if (parsedProps == null) {
      throw new SQLException(Messages.get("error.driver.badurl", url), "08001");
    }

    parsedProps = DefaultProperties.addDefaultProperties(parsedProps);

    Map propertyMap = new HashMap();
    Map descriptionMap = new HashMap();
    Messages.loadDriverProperties(propertyMap, descriptionMap);

    Map choicesMap = createChoicesMap();
    Map requiredTrueMap = createRequiredTrueMap();

    DriverPropertyInfo[] dpi = new DriverPropertyInfo[propertyMap.size()];
    Iterator iterator = propertyMap.entrySet().iterator();
    for (int i = 0; iterator.hasNext(); i++)
    {
      Map.Entry entry = (Map.Entry)iterator.next();
      String key = (String)entry.getKey();
      String name = (String)entry.getValue();

      DriverPropertyInfo info = new DriverPropertyInfo(name, parsedProps.getProperty(name));
      info.description = ((String)descriptionMap.get(key));
      info.required = requiredTrueMap.containsKey(name);

      if (choicesMap.containsKey(name)) {
        info.choices = ((String[])choicesMap.get(name));
      }

      dpi[i] = info;
    }

    return dpi;
  }

  private Properties setupConnectProperties(String url, Properties info)
    throws SQLException
  {
    Properties props = parseURL(url, info);

    if (props == null) {
      throw new SQLException(Messages.get("error.driver.badurl", url), "08001");
    }

    if (props.getProperty(Messages.get("prop.logintimeout")) == null) {
      props.setProperty(Messages.get("prop.logintimeout"), Integer.toString(DriverManager.getLoginTimeout()));
    }

    props = DefaultProperties.addDefaultProperties(props);
    return props;
  }

  private static Map createChoicesMap()
  {
    HashMap choicesMap = new HashMap();

    String[] booleanChoices = { "true", "false" };
    choicesMap.put(Messages.get("prop.cachemetadata"), booleanChoices);
    choicesMap.put(Messages.get("prop.lastupdatecount"), booleanChoices);
    choicesMap.put(Messages.get("prop.namedpipe"), booleanChoices);
    choicesMap.put(Messages.get("prop.tcpnodelay"), booleanChoices);
    choicesMap.put(Messages.get("prop.useunicode"), booleanChoices);
    choicesMap.put(Messages.get("prop.usecursors"), booleanChoices);
    choicesMap.put(Messages.get("prop.uselobs"), booleanChoices);
    choicesMap.put(Messages.get("prop.xaemulation"), booleanChoices);

    String[] prepareSqlChoices = { String.valueOf(0), String.valueOf(1), String.valueOf(2), String.valueOf(3) };

    choicesMap.put(Messages.get("prop.preparesql"), prepareSqlChoices);

    String[] serverTypeChoices = { String.valueOf(1), String.valueOf(2) };

    choicesMap.put(Messages.get("prop.servertype"), serverTypeChoices);

    String[] tdsChoices = { "4.2", "5.0", "7.0", "8.0" };

    choicesMap.put(Messages.get("prop.tds"), tdsChoices);

    String[] sslChoices = { "off", "request", "require", "authenticate" };

    choicesMap.put(Messages.get("prop.ssl"), sslChoices);

    return choicesMap;
  }

  private static Map createRequiredTrueMap()
  {
    HashMap requiredTrueMap = new HashMap();
    requiredTrueMap.put(Messages.get("prop.servername"), null);
    requiredTrueMap.put(Messages.get("prop.servertype"), null);
    return requiredTrueMap;
  }

  private static Properties parseURL(String url, Properties info)
  {
    Properties props = new Properties();

    for (Enumeration e = info.propertyNames(); e.hasMoreElements(); ) {
      String key = (String)e.nextElement();
      String value = info.getProperty(key);

      if (value != null) {
        props.setProperty(key.toUpperCase(), value);
      }
    }

    StringBuilder token = new StringBuilder(16);
    int pos = 0;

    pos = nextToken(url, pos, token);

    if (!"jdbc".equalsIgnoreCase(token.toString())) {
      return null;
    }

    pos = nextToken(url, pos, token);

    if (!"jtds".equalsIgnoreCase(token.toString())) {
      return null;
    }

    pos = nextToken(url, pos, token);
    String type = token.toString().toLowerCase();

    Integer serverType = DefaultProperties.getServerType(type);
    if (serverType == null) {
      return null;
    }
    props.setProperty(Messages.get("prop.servertype"), String.valueOf(serverType));

    pos = nextToken(url, pos, token);

    if (token.length() > 0) {
      return null;
    }

    pos = nextToken(url, pos, token);
    String host = token.toString();

    if (host.length() == 0) {
      host = props.getProperty(Messages.get("prop.servername"));
      if ((host == null) || (host.length() == 0)) {
        return null;
      }
    }

    props.setProperty(Messages.get("prop.servername"), host);

    if ((url.charAt(pos - 1) == ':') && (pos < url.length())) {
      pos = nextToken(url, pos, token);
      try
      {
        int port = Integer.parseInt(token.toString());
        props.setProperty(Messages.get("prop.portnumber"), Integer.toString(port));
      } catch (NumberFormatException e) {
        return null;
      }
    }

    if ((url.charAt(pos - 1) == '/') && (pos < url.length())) {
      pos = nextToken(url, pos, token);
      props.setProperty(Messages.get("prop.databasename"), token.toString());
    }

    while ((url.charAt(pos - 1) == ';') && (pos < url.length())) {
      pos = nextToken(url, pos, token);
      String tmp = token.toString();
      int index = tmp.indexOf(61);

      if ((index > 0) && (index < tmp.length() - 1))
        props.setProperty(tmp.substring(0, index).toUpperCase(), tmp.substring(index + 1));
      else {
        props.setProperty(tmp.toUpperCase(), "");
      }
    }

    return props;
  }

  private static int nextToken(String url, int pos, StringBuilder token)
  {
    token.setLength(0);
    boolean inQuote = false;
    while (pos < url.length()) {
      char ch = url.charAt(pos++);

      if (!inQuote) {
        if ((ch == ':') || (ch == ';'))
        {
          break;
        }
        if (ch == '/') {
          if ((pos >= url.length()) || (url.charAt(pos) != '/')) break;
          pos++; break;
        }

      }

      if (ch == '[') {
        inQuote = true;
      }
      else if (ch == ']') {
        inQuote = false;
      }
      else
      {
        token.append(ch);
      }
    }
    return pos;
  }

  public static void main(String[] args) {
    System.out.println(new StringBuilder().append("jTDS ").append(getVersion()).toString());
  }

  public Logger getParentLogger()
    throws SQLFeatureNotSupportedException
  {
    throw new AbstractMethodError();
  }

  static
  {
    try
    {
      DriverManager.registerDriver(new Driver());
    }
    catch (SQLException e)
    {
    }
  }
}

What is the issue here and I get the exception?
 
Upvote 0
Top