3

Hello i'm trying to get a mysql database connection with jython. I'm using Python 3.3.2 and Jython 2.5.3

My code looks like this:

import sys
from java.sql import *
sys.path.append("C:\\dev\\git\\LogAnalysis\\mysql-connector-java-5.0.8.jar")
con = DriveManager.getConnection("jdbc:mysql://localhost:3306/statistik", "root", "admin")
stmt = con.createStatement()
rs = stmt.executeQuery("SELECT * FROM search")

and so on. (Only a code snippet)

Each time i get the exeption:

java.sql.SQLException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/statistik

Can someone give me a tip?

user2814648
  • 421
  • 4
  • 12
  • See here http://stackoverflow.com/questions/12907260/jdbc-driver-not-found-error-in-monkeyrunner-jython – sunysen Sep 25 '13 at 11:09
  • Are you sure JDBC driver is in `c:\dev\git\...`? Also try to add code: `from java.lang import Class; Class.forName("com.mysql.jdbc.Driver")` – Michał Niklas Sep 26 '13 at 08:47

1 Answers1

4

See solution at: Jython CLASSPATH, sys.path and JDBC drivers

For me the easiest solution is to provide batch/shell script which sets CLASSPATH. This looks like:

SET CLASSPATH=C:\dev\git\LogAnalysis\mysql-connector-java-5.0.8.jar;%CLASSPATH%
CALL jython your_program.py %1 ...

Then you can remove line with:

sys.path.append(...)
Community
  • 1
  • 1
Michał Niklas
  • 53,067
  • 18
  • 70
  • 114