Java Question Referencing JTDS inside a new developed library

falbertini

Member
Licensed User
Longtime User
Hi,
I have succesfully created a library using Eclipse as explained in your tutorials, and everything works well.
I tried to add in my library a reference to JTDS, i have added in my class
@DependsOn(values={"jtds-1.2.5"})

Basic4Android compiles well, but when i call the routine i get this error:
"No message resource found for message property prop.servertype"

The routine does this:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
DriverManager.getConnection ...

Do you have any ideas? Is there a way to solve this?

Thanks in advance
Bye
 

falbertini

Member
Licensed User
Longtime User
Thanks for the answer, here is the complete log (from Logs tab):

LogCat connected to: 80A354043046227015
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


<!>anywheresoftware.b4a.keywords.Common 151<!> ** Activity (main) Create, isFirst = true **


<!>anywheresoftware.b4a.keywords.Common 151<!> ** Activity (main) Resume **
<!>anywheresoftware.b4a.keywords.Common 151<!> ** Activity (main) Create, isFirst = true **
<!>anywheresoftware.b4a.keywords.Common 151<!> ** Activity (main) Resume **
<!>anywheresoftware.b4a.keywords.Common 151<!> ** Activity (main) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 150<!> main_prova (B4A line: 102)
errore = lib.ConnectDBProduzione("192.170.0.4","1433","NomeDB","USER","PASS")

java.lang.RuntimeException: No message resource found for message property prop.servertype
at net.sourceforge.jtds.jdbc.Messages.get(Messages.java:120)
at net.sourceforge.jtds.jdbc.Messages.get(Messages.java:67)
at net.sourceforge.jtds.jdbc.Driver.parseURL(Driver.java:377)
at net.sourceforge.jtds.jdbc.Driver.setupConnectProperties(Driver.java:242)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:181)
at java.sql.DriverManager.getConnection(DriverManager.java:180)
at java.sql.DriverManager.getConnection(DriverManager.java:214)
at com.filippoalbertini.LibSvi.ConnectDBProduzione(LibSvi.java:52)
at com.filippoalbertini.scuola.main._prova(main.java:680)
at com.filippoalbertini.scuola.main._activity_create(main.java:255)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at com.filippoalbertini.scuola.main.afterFirstLayout(main.java:84)
at com.filippoalbertini.scuola.main.access$100(main.java:16)
at com.filippoalbertini.scuola.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3729)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
at dalvik.system.NativeStart.main(Native Method)
<!>anywheresoftware.b4a.BA 156<!> java.lang.RuntimeException: No message resource found for message property prop.servertype
 

falbertini

Member
Licensed User
Longtime User
Maybe i am making some mistake when i export into jar from Eclipse..
Sorry but i am a beginner with Ecplise..

Here is how is configured Ecplise:
2012-02-06%2017h25_54.jpg
 

falbertini

Member
Licensed User
Longtime User
Searching in the web i found this:
Dynamic loading of JDBC drivers

I tried that DriverShim, copying the jtds jar in the sdcard folder and using this code:

B4X:
URL u;
u = new URL("jar:file:/sdcard/jtds-1.2.5.jar!/");

String classname = "net.sourceforge.jtds.jdbc.Driver";
URLClassLoader ucl = new URLClassLoader(new URL[] { u });
Driver d = (Driver) Class.forName(classname, true, ucl).newInstance();
DriverManager.registerDriver(new DriverShim(d));

Connection cnnDbMaster;
cnnDbMaster = DriverManager.getConnection(
      "jdbc:jtds:sqlserver://" + db_server + ":" + db_port
            + "/" + db_name, db_user, db_pass);

With this code i get ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver

Is there something wrong? How can i fix this ?
Thanks
 

falbertini

Member
Licensed User
Longtime User
Hi Erel, thanks for your answers..
I used JTDS for direct connection from Android device to SqlServer and everything worked fine with my old programs in Eclipse...
Using B4a i can't find a way to make this works

Here you can find a little eclipse project:
http://dl.dropbox.com/u/9960822/Jdbc.zip

Do you have any ideas how to fix this ? any work around or something ?
It is really important for me, becouse it is the core of my application
Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is with a resource file named net\sourceforge\jtds\jdbc\Charset.properties.

It gets lost during compilation. You should download this library source code and modify CharsetInfo.java to load this resource from the assets file.
You can add a reference to B4A Core.jar and then use the following code:
B4X:
stream = File.OpenInput(File.getDirAssets(), "charset.properties").getObject();

You will need to add charset.properties to the Files tab in your project.
 

falbertini

Member
Licensed User
Longtime User
Hi, thanks for your hints.
I have tried what you said, i have downloaded Jtds source (1.2.5) and modified the CharsetInfo.java (C) and then i have build the resulting project (D)..
Because i am not very expert in Java and don't know how to create jar, i copied the new Class generated with 7Zip on the original Jar (E).
Then i have executed the b4a Jdbc project (F) but i still get the same error (H)

Sure i am doing something wrong, can you create the correct Jar? (on bottom you can find a link with the Jtds sources modified)

http://dl.dropbox.com/u/9960822/Jtds_With_Details.zip

Files attached:
A) Modify to the Import in CharsetInfo.jpg
B) Modify to the source CharsetInfo.jpg
C) CharsetInfo.java
D) jtds-1.2.5.jar (modified)
E) Jar creation.jpg
F) B4aJdbc (folder with b4 project)
G) B4 project image.jpg
H) Error on device.png

Here you can find the complete Jtds folder with sources
http://dl.dropbox.com/u/9960822/jtds-1.2.5_source_modified.zip


Very very thanks :eek:
 

falbertini

Member
Licensed User
Longtime User
Hi,
the error message is the same:

"No message resource found for message property prop.servertype"
 

begale

Member
Licensed User
Longtime User
jtds

Hi, did you have find a solution ?
I want connect to MS SQL server from my device with B4Android
 

hasanaydin52

Member
Licensed User
Longtime User
jdbc

Hello Erel and Falbertini,

I have same error and same project.

Problem solved when jtds-1.2.5.jar file copy to b4a additionallibrary folder.

I can connect MSSQL Server by Library.
 

falbertini

Member
Licensed User
Longtime User
Hi hasanaydin52,
I am very happy to hear that jtds with you works..
Can you give me an example of the working code you use?
Did you use the original jtds-1.2.5.jar downloaded from the JTDS website without any modifications?
Thanks,
Bye
 
Top