Issue with Connecting My SQL

Hi Guys,

I need to connect My SQL server with WF, am using the below code in my web harvest XML but no luck, facing below issue.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Will my WF allows download from Maven?

    import groovy.sql.Sql
	this.class.classLoader.addURL(new URL("http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar"))
	
	def url = 'jdbc:mysql://localhost:3306/sakila'
	def user = 'root'
	def password = 'admin'
	def driver = 'com.mysql.jdbc.Driver'
	def sql = Sql.newInstance(url, user, password, driver)

	sql.execute '''
	  select first_name from actor
	'''

	sql.close()

Any help or suggestions much appreciated?

jdbc uses different classloader than groovy/beanshell. In order for it to properly work - the jar need to be added to the classpath before WorkFusion App or WorkFusion Studio start up.
Note:
WorkFusion App server comes with mysql driver pre-packaged (tomcat/lib/mysql-connector-java-5.1.15.jar), so on the WorkFusion server the code should work fine without adding extra jar.
In WorkFusion Studio - add the jar to the Eclipse classpath.

Also check out the out-of-the-box database plugin (http://web-harvest.sourceforge.net/manual.php#database).
Code would look something like following:

    <database connection="jdbc:mysql://localhost:3306/sakila" jdbcclass="com.mysql.jdbc.Driver"
    		username="user" password="securepassword">

    		select first_name from actor
    </database>

@azhemoytuk Thank you very much, worked for me. Cheers!!

1 Like

hi

can u please share the screen shot how u have connect the MySQL connectivity with workfusion from scratch, I am new to it and very confused with this part. Please help .

Thanks
Jasnoor kaur

2 Likes