JDBC driver not found error in monkeyrunner/jython

懵懂的女人 提交于 2019-12-12 17:15:34

问题


I need to Insert something in the DB. im using JDBC as a connector, jython the script, mysql the DB and the script is running in CentOS.

my code looks something like this:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

from com.ziclix.python.sql import zxJDBC

  db=zxJDBC.connect("jdbc:mysql://XXX.XXX.XXX.XXX:3306/dbname","USER","PASSWORD","org.gjt.mm.mysql.Driver")

c=db.cursor() c.execute("INSERT INTO tablename values ('X','X','X')")

before that, I downloaded and decompressed the file from here (in the desktop)

I added the path to classpath by doing this

 export PATH=/home/XX/Desktop/mysql-connector-java-5.1.22

and when I ran the script, it gave me this error

zxJDBC.DatabaseError.driver [org.gjt.mm.mysql.Driver] not found

what have I done wrong? is the name of the driver name correct? because I just copied it in one of the tutorials that I've seen. or probably did I install the driver correctly?

Thanks.


回答1:


this is how I managed to solve the error:

  1. Download the JDBC driver here

  2. Extract the tar.gz file anywhere you want.

  3. You will find mysql-connector-java-5.1.22-bin.jar inside that folder. Copy that and paste to (in my case) /%android-sdk%/tools/lib

  4. Add the new location of mysql-connector-java-5.1.22-bin.jar to classpath

  5. do the script like this

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

from com.ziclix.python.sql import zxJDBC

db=zxJDBC.connect("jdbc:mysql://XXX.XXX.XXX.XXX:3306/dbname","USER","PASSWORD","com.mysql.jdbc.Driver")

c=db.cursor()

c.execute("INSERT INTO tablename values ('X','X','X')")

db.commit()

Hope this helps to those who will need it in the future. :)




回答2:


How are you running jython? If you're using the standalone install, i.e. java -jar jython.jar, then from the Java Documentation ...

-jar

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

... you can't add anything to the classpath. Repackaging the required classes into the jython jar is one approach or this answer has an alternative solution - basically add the jython.jar to the classpath too (either using -cp or CLASSPATH) and run the org.python.util.jython class directly.




回答3:


I got the sample problem in windows7,I slove this problem by this:

  1. download the JDBC driver
  2. add the mysql-connector-java-ver-bin.jar to envionment variables: such as: CLASSPATH : C:\xxx-path\mysql-connector-java-5.1.41-bin.jar

then I slove this problem



来源:https://stackoverflow.com/questions/12907260/jdbc-driver-not-found-error-in-monkeyrunner-jython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!