(Necessitas)Microsoft sql db access gives error in opening - android

I wrote a program to access Microsoft sql database. It works fine in desktop. But when I run same program in android device I’m getting error:
04-09 06:17:41.784: W/Qt(1240): kernel\qsqlquery.cpp:368 (bool
QSqlQuery::exec(const QString&)): QSqlQuery::exec: database not open
Here is my code:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={SQL Server};Server=192.168.1.3;Database=sms_exp;");
db.setUserName("sa");
db.setPassword("xxxxxyy");
if(!db.open())
{
qDebug ("Error");
}
else
{
qDebug ("OK");
}
QSqlQuery query (db);
query.exec("SELECT item_code, item_des FROM prod_mast WHERE item_code = 0100000210");
while (query.next())
{
QString name1 = query.value(0).toString();
QString name2 = query.value(1).toString();
qDebug (qPrintable(name1));
qDebug (qPrintable(name2));
}
db.close();

There is no Android build of the ODBC driver. If you check QSqlDatabase::drivers() you will see that only SQLite driver is supported for android in Qt.
The only way of making an ODBC connection on android is to use a JDBC-ODBC bridge that supports network connections between the client and the server. JDBC on Android to ODBC on a windows machine and then to the MS Access ODBC driver.

Related

how to copy files from android to windows share using python?

Im trying to copy some files to and from a windows share. I am using python 2.7 and the pysmb library. This works fine with win7, but not with android. I build my connection over VPN with SMBConnection. listShares and listPath is working. Under win7 there is no problem using also os.path.isdir or shutil.copyfile. But that does not work with android. This is my code:
server_name = '192.168.168.12'
conn = SMBConnection(username=username, password=password, my_name='waldi2'
remote_name=server_name, domain=domain, use_ntlm_v2=True,
sign_options=SMBConnection.SIGN_WHEN_SUPPORTED, is_direct_tcp=True)
connected = conn.connect(server_name, 445)
# obtain a list of shares:
Response = conn.listShares(timeout=30) # !!!working, shows e.g.(' Share[', 20, '] =', u'JBW_in')
os.path.isdir('//192.168.168.12/JBW_in/') # is False with android, True with win7 !??
shutil.copyfile('/sdcard/waldi2_0/data/stop.txt', '//192.168.168.12/JBW_in/stop.txt')
This is no prob with win7, but with android it throws:
[Errno 2] No such file or directory: '//192.168.168.12/JBW_in/stop.txt'
Any clues? would be very very welcome ....
Or maybe alternative approaches to manage some python-based file-exchange between android and windows-server.
If I understund you correctly you are trying to connect to an android device via SMB. By my knowledge android doesnt have support for SMB server natively, but you could install a third-party app with a SMB server.

app won't recognize function in non-android jar

I am writing an app to connect to a database on a server (AS400 server using SQL to talk to the database). IBM supplies a java toolbox to access the server in a jar called jt400android.
I have a test function:
protected void ConnectionTest()
{
AS400 system = new AS400("jc400");
try
{
system.connectService(AS400.RECORDACCESS);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(0);
}
}
AS400 is a function included in the jt400android.jar in com.ibm.as400.access.* that handles socket protocol, connections, and authentication to an AS400 machine. (I've resorted to this method as JDBC is apparently not a good way to go).
The code compiles just fine, no errors or warnings, but when I run the apk on my AVD, I get this error
03-12 22:44:30.300: E/dalvikvm(484): Could not find class 'com.ibm.as400.access.AS400', referenced from method jcpaper.android.jc400droid.MainActivity.ConnectionTest
I've searched the forums and tried the following suggestions:
added the jar to Java Build Path > Libraries (did this to make the code compile)
checked jar on Java Build Path > Order and Export
included a copy of the jar in [project folder]/libs
Each time I end up with the same could not find class error.
I'm running Eclipse for mobile (Juno v1) on Windows XP, building for Android 2.3.3.
Any suggestions on what's happening here?
The JTOpen Lite/JTLite libraries might provide a better way of connecting to your server. These libraries are new from IBM and are designed for specific use on Android devices.
JTOpen Lite - IBM Developer Works
JTOpen Lite Javadoc
Make sure that you add the .jar to the build path and export the libraries properly.
The record level access method that you are trying to use is an older method for connecting applications to DB2 databases, so you will probably have a harder time finding information about it.

Running monkeyrunner python script with mySQL

I am trying to use MySQL to store my results with my monkeyrunner script. I am getting this error:
import MySQLdb
ImportError: No module named named MySQLdb
I write my monkeyrunner script using python. I run the scripts on android-sdk/tools folder where monkeyrunner is located. And I already setup python-mySQL connection, it's working fine when I run python scripts inside Python27 folder(not inside Android)
How do I import MySQLdb to my monkeyrunner script?
Thanks.
Monkeyrunner uses jython, not python. Hence, you are able to connect to mysqldb using python scripts. Not using the jython script.
From monkeyrunner, to access mySQL you should use zxJDBC package for jython.
Add JDBC driver in your monkeyrunner class path.
The zxJDBC package provides a nearly 100% Python DB API 2.0 compliant interface for database connectivity in Jython
And following code should get you to connect to the mysql database.
from com.ziclix.python.sql import zxJDBC
params = {}
params['serverName'] = 'localhost'
params['databaseName'] = 'ziclix'
params['user'] = None
params['password'] = None
params['port'] = 3306
db = apply(zxJDBC.connectx, ("org.gjt.mm.mysql.MysqlDataSource",), params)
Below link can elaborate more on this.
http://www.jython.org/archive/21/docs/zxjdbc.html
Keep it simple. Instead of dealing with jars, versions, and other stuff just use the command line:
#! /opt/android-sdk/tools/monkeyrunner
import subprocess
USER = 'myuser'
PASSWORD = 'mypass'
DB = 'mydb'
p1 = subprocess.Popen([ "mysql", "--user=%s" % USER, "--password=%s" % PASSWORD, DB ], stdin=subprocess.PIPE)
print p1.communicate('INSERT INTO t1 VALUES(1, "other")')

Run python Script in android application

I want to get list of installed software on remote computer.For that I want to use python script in my android application.Now,I have a python script which is getting the list of installed software on remote computer.But,I don't know how to make it supported in android.
For this, I found SL4A android Scripting here . So, I tried to run my python script in android device using SL4A.But,It's not working and giving me error because some packages like win32.client is missing.I don't know more about SL4A so I don't know how to convert my python script in Android supported form.So,anyone have any idea or code please suggest me.....
Also If anyone have another way to get installed software list from remote Pc then please suggest...
Below is my python script
import wmi
from winreg import (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, QueryValueEx)
c = wmi.WMI(computer="PC02",user="admin",password="a#1",namespace="root/default").StdRegProv
result, names = c.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall")
print('These subkeys are found under "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"\n\n')
separator = "*" * 80
keyPath = r"Software\Microsoft\Windows\CurrentVersion\Uninstall"
count = 0
while count < len(names):
try:
print(separator+'\n')
path = keyPath + "\\" + names[count]
key = OpenKey(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS)
temp = QueryValueEx(key, 'DisplayName')
display = str(temp[0])
print (" Name: "+display+'\n',"key:",names[count])
count += 1
except:
print ("Key:",names[count])
count += 1
continue
Run the script on your remote computer, and expose the list of installed software on HTTP, a good way to write this simple web app is to use flask and its development server to serve the list of installed software, then write a python script which uses the native android web interface to fetch the list and display it.
You are having problems with missing libraries because you are importing windows specific ones. At any rate, this isn't the correct script to be running. This script seems to be for a computer, not an android phone.
You're trying to use a Python script that uses Windows Management Instrumentation (WMI), on a device that doesn't have that library.
Sadly, WMI on Python requires the win32 library, which is only available on Windows. I don't think you're going to have much success on checking the installed programs on remote Windows computer from an Android device in this way.
Since WMI is based on WBEM, you may be able to use wbem to access it; you might want to try using pywbem, a pure python wbem library.
Running python scripts is now achievable in gradle system using Tasks
task pythonFile(type:Exec) {
workingDir 'src_path'
commandLine 'python', 'my_script.py'
}

Writing raw data to the Android Serial Port (USB)

I need to write some "raw" data to the usb port for a project of mine (no prob if root should be required).
I found a port of libusb for Android and managed to compile it with NDK. I linked the library to an executable of mine (executed as root), but the function "libusb_init" always returns an error (LIBUSB_ERROR_OTHER).
I found that the problem (by now...) is in the file "linux_usbfs.c", more precisely in this function:
static const char *find_usbfs_path(void)
{
const char *path = "/dev/bus/usb";
const char *ret = NULL;
if (check_usb_vfs(path)) {
ret = path;
} else {
path = "/proc/bus/usb";
if (check_usb_vfs(path))
ret = path;
}
usbi_dbg("found usbfs at %s", ret);
return ret;
}
/dev/bus/usb obviously doesn't exist on my N1.
Why not try pyserial? python seems simpler for me. You need either a kernel with usb host mode or your phone supports serial over a ttyMSM0 natively, which you need to find out. Once you are sure you have a serial port on your phone, look at this link which is meant for huawei ideos U8150, but the pyserial stuff done using python for android is the alternative I am suggesting.

Categories

Resources