2

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.

srh snl
  • 797
  • 1
  • 19
  • 42
  • i hope you have assigned the right jar to the classpath ?make sure that the jar is readable with the permissions? – thar45 Oct 16 '12 at 04:37
  • @Thanga how do I know which one is the correct jar? I found 1 jar in root folder of the extracted file. It is named mysql-connector-java-5.1.22-bin.jar . And then I copied path of that file and tried to put it add it in the classpath by doing what is stated above. how do I know thatitreadeacle wth permission? Thanks a lot :) – srh snl Oct 16 '12 at 06:29

3 Answers3

3

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. :)

Community
  • 1
  • 1
srh snl
  • 797
  • 1
  • 19
  • 42
0

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.

Community
  • 1
  • 1
Jeremy Gosling
  • 1,130
  • 10
  • 11
-1

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

  • Despite the different path – which can obviously change between systems – this solution is very similar to the OP's one: http://stackoverflow.com/a/12909198/1128918 – Gustavo Straube Apr 10 '17 at 12:07