Domanda

first of all maybe this could be a repost of: https://stackoverflow.com/questions/13078271/trying-to-use-jtds-in-android-project, not sure, but seems there's no answer in that post i´ll try it here, issue is, im trying to connect to a MS SQL 2k5 via JTDS (though the JTDS connection is just fine, i tried it on a pure java test and could connect successfully) on android with ADT (eclipse) and it can't found the class in classpath getting the typical Exception ClassNotFoundException, as i did encounter with this problem before i did all i know for solve it (except for running the program via command line with "java -cp" , cause i don't know how to do that with dalvik, so i set the classpath via "build path" eclipse option, put the jar at libs/, after xxx times of failure getting the exception i erase all the jars in libs/ and remove all the jars via "build path" option, clean the project and restart eclipse, set up jars again, still got the same exception, still pending; configuring the varible via windows classpath variable, any other ideas guys?

Software: Windows 7 professional 32 bits jdk 1.7 ADT eclipse jtds 1.3 (latest by now in their web page) MS SQL 2k5 android 4.2.2

note: if need the code, ask for it (i don't think is necessary, same code runs flawless in pure java via netbeans with the same jtds).

È stato utile?

Soluzione

seems like this is a hard topic to touch (cause of no answer) anyway, i solve the problem, here i will leave it step by step.

1: install MS SQL 2k5 (be aware of put the db access on mixed (window auth and SQL user/pass and extrictly put a password for SA user this is mandatory)

2: install MS SQL management studio (if you want to make things more easy, this is optional) to create database via GUI and prove that what you are inserting (or whatever you are doing to DB) with the android device is really being done.

3: configure your MS SQL, go to: SQL server configuration manager; SQL Express protocols; TCP/IP in the first tab (protocol) put "enabled" to yes, then in the IP tab, put ipv4 to enabled YES, ipv2 enabled to yes and at IPALL put TCP port to 1433.

4: now go to your jtds-1.2.x-dist folder and enter to x86 (if 32 bits OS in case 64 then x64 folder) then SSO and copy ntlmauth.dll to you jdk/bin or jre/bin folder.

5: i won't paste all my code here but the String connection is an important thing:

conn = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.3.67:1433/androiddb", "sa", "1013")

6: be aware that the ip used for connecting from an android device is the ipv2 and not the ipv4 default 127.0.0.1 or localhost if you use any of those it won't work, use the ipv2 version.

i test this from a real android device, exactly the samsung galaxy tab, if you try it from an emulator maybe you must use the 10.0.2.2 ip, not sure about this since i didn't test it, one more important thing, by the time i wrote this 1.3.0 jtds wasn't working for android 4.2, that's why i said in jtds step to look at your jtds-1.2.x-dist, you must use 1.2.x version by now.

hope this to be helpful to anyone, regards.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top