Using mysql in an URcap

Hello comunity,

has anyone ever programmed a URcap that is communicating directly to a MySQL database ? I mean specifcally the jdbc.driver from mysql package.

I have been seraching the internet space, but so far haven t found anybody talking about this ?

Thank You,
Goce

Hi Goce,

With the jdbc.driver I opened the dependency-hell :upside_down_face: …
and went back to sql4automation

Mike

modifying Embed-Dependency (mentioned here) it is working with current mysql-connector-java (8.0.19) tested on ursim 5.6

pom:

<Import-Package>
	com.ur.urcap.api*; mysql*;resolution:=optional,com.google.protobuf.*;resolution:=optional,com.mchange.*;resolution:=optional,org.jboss.resource.*;resolution:=optional,org.slf4j*;resolution:=optional, * 							
</Import-Package>

<Embed-Dependency>
	!mysql, !org.osgi.core, !com.ur.urcap.api, *; scope=compile|runtime 																			
</Embed-Dependency>

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.19</version>
</dependency>

edit:
and tested on a real robot

1 Like

Thank you @m.nagel , we did exactly as you wrote and the part for the mysql connector issue was fixed.

Hi @m.nagel ,

I have followed the instructions you have suggested but I still receive the error below.
“java.sql.SQLException: No suitable driver found for jdbc:mysql://-------”

Do you have any idea where do I go wrong? do you have any example of urcap project that I could investigate to figure out?

thanks in advance.

John

Hi John,

which version of mysql-connector-java did you try?

...
 <dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.19</version>
</dependency>
...

if I remember correctly, I had some trouble depending on the version.

Mike

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.23</version>
</dependency>

mysql-connector-java 8.0.23
Starter Package for SDK 1.10.0
URSim 5.8.0
MySQL Server 8.0.23 (running on different workstation)

is working for me in VM. In your build /target/yourfile.urcap is there mysql-connector-java-8.0.23.jar included?

In my pom.xml: Import-Package & Embed-Dependency are looking like that:

<Import-Package>
	com.ur.urcap.api*;						 
	mysql*;							
	resolution:=optional,
	com.google.protobuf.*;
	resolution:=optional,
	com.mchange.*;
	resolution:=optional,
	org.jboss.resource.*;
	resolution:=optional,							
	org.slf4j*;							
	resolution:=optional, * 							
</Import-Package>	

<Embed-Dependency>
	!mysql, 
	!org.osgi.core, 
	!com.ur.urcap.api, *; 
	scope=compile|runtime 																			
</Embed-Dependency>	

...

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.23</version>
</dependency>

I have fixed the issue by adding the code " Class.forName(“com.mysql.jdbc.Driver”); before the connection command to the database

thanks.

Have you ever tested it in the real robot (cb3 or e)?
It failed to work when I try to activate it in the cb3 although it was functional in VM.
my assumption is JDBC connector requires at least JDK 8 but the cobot has JDK 6.

UR3e with current version of UR Polyscope at that time - probably 5.6.x

e series come with the jdk8 java package which is the same as URCaps Starter Package. the code was working with both
now my question is: how could we activate that MySQL functionality in cb3 which uses JDK6?

what are the risks if we update the polyscope version from JDK6 to JDK8?

you could try to use mysql-connector-java 5.1.x
currently I have no CB available for a test

https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-versions.html

eg:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.49</version>
</dependency>

does not work with that connector.

Have you got a solution to Error: “java.lang.IllegalStateException: Cannot find the driver in the classpath!” ?
I’m trying to add JAR file into project but seems to be impossible.