How to use ebean and mysql in play framework? - mysql

Im trying to create small CRUD application using play-java template.
Im using typesafe activator through cmd I create new project so now i want enable ebean and have to change mysql database. im using activator 1.3.6,
for sql im using my phpmyadmin sql 5.6.20 i googled and i did everything like documentary but still i couldn't solve my problem i couldn't add ebean my project and i couldn't connect mysql connector i did changes using this links
Ebean Mysql stackoverflow question but no use i wasted 3 days then i used play2-crud template enter link description here in this i can use eban but i dont know how to enable mysql and im using INTELLIJ IDE if anyone expert help me

To enable MySQL
in the application.conf file:
# Database configuration using MySQL database engine
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://127.0.0.1/mydataabse"
db.default.username=yourusername
db.default.password="yourpassword"
and you also need to add MySQL connector to the build.sbt libraryDependencies:
libraryDependencies ++= Seq(
...
"mysql" % "mysql-connector-java" % "5.1.18"
)
To enable Ebean
Add Ebean plugin In to the project\plugins.sbt:
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
Enable this plugin in the build.sbt:
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
Configure Ebean in the conf\application.conf to take models from your model package:
ebean.default = ["my.models.*"]

Related

Run Liquibase over Wix Embedded MySql

Currently I have some new modules using Spring Boot and a H2 embedded database for functional testing.
The legacy module works with a lot of Liquibase scripts to construct the whole database.
I was looking to use Wix Embedded Mysql to make the test database more production-like. After read the docs I did not find anything specific about how to handle scripts using tools like Liquibase or Flyway.
Is it possible to execute a Liquibase goal on this embedded database after his startup?
After a few days of research, yes, there is a way of running Liquibase over Wix Embedded MySQL.
Here is the step by step:
Configuring Wix Embedded Database
The configuration around Wix is pretty straight forward as described on their GitHub:
MysqldConfig config = aMysqldConfig(v5_7_latest)
.withCharset(UTF8)
.withPort(3060)
.withUser("myuser", "mypassword")
.withTimeZone("America/Sao_Paulo")
.build();
EmbeddedMysql mysqld = anEmbeddedMysql(config)
.addSchema("myschema")
.start();
Liquibase configuration
I have added the Liquibase maven dependency on my project, so we have access to Liquibase code programmatically, the API can be found here.
First we have to build a datasource and pass to Liquibase find the correct implementation of our database, with the result we can then manipulate the Liquibase object to execute the goals:
DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.username(mysqld.getConfig().getUsername());
dataSourceBuilder.password(mysqld.getConfig().getPassword());
dataSourceBuilder.driverClassName(com.mysql.jdbc.Driver.class.getName());
dataSourceBuilder.url("jdbc:mysql://localhost:3060/myschema");
DataSource dataSource = dataSourceBuilder.build();
Database database = DatabaseFactory
.getInstance()
.findCorrectDatabaseImplementation(
new JdbcConnection(dataSource.getConnection()) // Fetch MySQL database implementation
);
Liquibase liquibase = new Liquibase("liquibase/mychanges.xml", // Path to liquibase changes
new ClassLoaderResourceAccessor(),
database);
liquibase.update(new Contexts()); // This execute the liquibase:update on the embedded database

How to add a JDBC driver to a Jenkins pipeline?

I want to create a database within a pipeline script to be used by the deployed app. But first I started testing the connection. I got this problem:
java.sql.SQLException: No suitable driver found for jdbc:mysql://mysql:3306/test_db
I have the database plugin and the MySQL database plugin installed.
How do I get the JDBC driver?
import groovy.sql.Sql
node{
def sql = Sql.newInstance("jdbc:mysql://mysql:3306/test_db", "user","passwd", "com.mysql.jdbc.Driver")
def rows = sql.execute "select count(*) from test_table;"
echo rows.dump()
}
Update after albciff answer:
My versions of:
Jenkins = 2.19.1
Database plugin = 1.5
Mysql database plugin = 1.1
The latest test script.
import groovy.sql.Sql
Class.forName("com.mysql.jdbc.Driver")
Which throws:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From the MySQL DataBase Plugin documentation you can see that jdbc drivers for MySQL are included:
Note that MySQL JDBC driver is under GPLv2 with FOSS exception. This
plugin by itself qualifies under the FOSS exception, but if you are
redistributing this plugin, please do check the license terms.
Drizzle(+MySQL) Database Plugin is available as an alternative to this
plugin, and that one is under the BSD license.
More concretely the actual last version (1.1) for this plugin contains connector version 5.1.38:
Version 1.1 (May 21, 2016) mysql-connector version 5.1.38
So probably in order to have the driver available you have to force the driver to be registered.
To do so use Class.forName("com.mysql.jdbc.Driver") before instantiate the connection in your code:
import groovy.sql.Sql
node{
Class.forName("com.mysql.jdbc.Driver")
def sql = Sql.newInstance("jdbc:mysql://mysql:3306/test_db", "user","passwd", "com.mysql.jdbc.Driver")
def rows = sql.execute "select count(*) from test_table;"
echo rows.dump()
}
UPDATE:
In order to has the JDBC connector classes available in the Jenkins pipeline groovy scripts you need to update the DataBase plugin to last currently version:
Version 1.5 (May 30, 2016) Pipeline Support
You can simply add the java connector in the java class path.
If jenkins is running java < 9 you probably will find the right place inside something like that:
<java_home>/jre/lib/ext
If jenkins is running java >= 9 you probably will find the right place inside something like that:
/usr/share/jenkins/jenkins.war
To find your paths you can check:
http://your.jenkins.host/systemInfo (or navigate system info path by GUI) and search for java.ext.dirs or java.class.path
http://your.jenkins.host/script (running console script such as System.getProperty("java.ext.dirs") or System.getProperty("java.class.path"))
This snippet can help you with the jenkins.war thing when running inside docker:
#adding extra jars to default jenkins java classpath (/usr/share/jenkins/jenkins.war)
RUN sudo mkdir -p /usr/share/jenkins/WEB-INF/lib/
RUN whereis jar #just to find full jar command classpath to use with sudo
COPY ./jar-ext/groovy/mysql-connector-java-8.0.21.jar /usr/share/jenkins/WEB-INF/lib/
RUN cd /usr/share/jenkins && sudo /opt/java/openjdk/bin/jar -uvf jenkins.war ./WEB-INF/lib/mysql-connector-java-8.0.21.jar
For Jenkins running on Java >= 9 add the jdbc drivers under ${JENKINS_HOME}/war/WEB-INF/lib and under the --webroot directory.

xcode: Mysql connector library not work on iphone5 (armv7s) ,any solution?

I built my App using Mysql Connector/C to connect a remote Mysql database, its works fine on the simulator (no errors, no warnings) but when i try to run it on my device (iphone5) i got this error:
No architectures to compile for (ARCHS=armv7 armv7s, VALID_ARCHS=armv7 armv7s)
i tried -as in some answers- to change setting (Architectures - Build Active Architectures- Valid Architectures) but the error still, only when i change the setting (Architectures & Valid Architectures) to "armv6" its build without error but many warnings appears says:
warning: no rule to process file '(my App dir)/main.m' of type sourcecode.c.objc for architecture armv6
and also for all .m files, when i tried to start the App i got message:
Xcode cannot run using selected device
I know that the Connector library need to update , but are there any solution ?
your need compile the connector lib in xcode for iOS (armv6, armv7, armv7s, i386), then use lipo tool to combine output libs.
direct connect your mysql in app is not safe, a suggest way is setup a Apache+PHP+MySQL server, then on iPhone useing ASIHTTPRequest to connect your server.

Mysql dependencies in securesocial

I am trying to use mysql 5.5.27 database into securesocial sbt-version 0.12.2 with play 2.1.0. What changes should I include into the variable appdependencies in Build.scala to include the mysql?
Add a line in the form:
"mysql" % "mysql-connector-java" % "5.1.18" // mySQL driver
in your appDependencies variable Seq.
Hope this helps.

Multiple MySQL queries with Ruby

I'm having troubles with MySQL queries in Ruby. I use 'mysql' gem.
Configuration is stored in a separate yml file and loaded into #conf variable.
This is my code:
# connect to the database
Mysql::new(#conf['sql_host'], #conf['sql_user'], #conf['sql_password'], #conf['sql_base'])
# it's ok when we're doing this
my.query("SELECT * FROM `my_table`") do |e|
# code
end
# Maybe, I've missed something here...
# really this query will insert value into other table, used SELECT just for testing
# this throws exception: 'query: not connected'
my.query("SELECT * FROM `my_table_2`")
Windows XP
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
mysql (2.8.1, 2.7.3)
MySQL client version: 5.0.51a
Second query throws 'query: not connected'.
First of all, your program looks ok. I am 100% sure you have libmysql.dll version problem.
I can reproduce this with libmysql.dll provided from Mysql installer.
Download this file and replace in c:\ruby\bin\
http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll
and re-run your program without any change.
Related issue and credit to here
I have run into immeasurable problems when attempting to use Ruby's mysql gem on any version of Windows. From what I can tell, it simply doesn't work unless you can figure out how to compile it yourself (which is a royal pain in the ass).
Have you considered using ActiveRecord as your ORM (object relational mapping) layer and doing development with SQLite or some other database on Windows and then running the production environment on Linux with MySQL? This is the solution that I took a while back and it worked out quite well.