Adding 2 session variables in JDBC MySql Connection string - mysql

I need to add 2 session variables in JDBC connection string.
sessionVariables=FOREIGN_KEY_CHECKS=0&sessionVariables=SQL_SAFE_UPDATES=0
The second one is overwriting the first variable. Is there any option in JDBC connection to add 2 session variables?

We can pass this as comma separated like sessionVariables=group_concat_max_len=204800,time_zone='-00:00'

Related

How to get max_allocated_packets from JDBC connection from a Slick DB connection to MySQL

Is there a way via Scala with Slick database query and access library (or using other tricks - dare I say mocks?) to get max_allocated_packets from JDBC-read connection properties from a Slick-style DB connection to MySQL?
As I suspect, the code makes several touch type actions at deeper levels and this connection property is then populated.
Ex: Once a connection is made in com.mysql.cj.jdbc.ConnectionImpl ... using Scala with the Slick library... the value for the JDBC connect property of max_allocated_packets is within the object (debugged in IntelliJ). How can I extract this value or obtain it in higher level code as asked above?
Of course I can query the DB directly to get that value, but I am hoping I can extract this property after the setup phase.
If the value is publically available on a connection, you could try to use SimpleDBIO action to access the JDBC-level values.
See: https://scala-slick.org/doc/3.2.0/dbio.html#jdbc-interoperability
It would be of the form:
val getMaxPacketAction = SimpleDBIO[Int] { database =>
// make use of database.connection here
}
However, this is still going to the database for a connection, so it may be just easier to query for the value you want.

More that one logical-name for database in parameter file (.pf)?

I have a parameter file (.pf) with different databases to connect. The databases have multiple aliases therefore I want to set the logical names of each database.
-db physical_database_name
-ld [Logical name/alias]
- [...]
When I set more -ld parameters than one, it takes only the last one.
How is it possible to set more than one alias in the Parameter file (.pf)?
Additional aliases can only be set through code.
What you could do is to use the -param Startup Parameter.
-param dbname1=alias1,alias2|dbname2=alias3,alias4
And process this string based SESSION:PARAMETER in your startup procedure.

Parameter index out of range MySQL PreparedStatement?

I try to do a select:
but I receive an Exception:
Try it like that:
preparedStatement = connection.prepareStatement(sqlCompetition);
preparedStatement.setInt(...);
I think you have still the old statement in the variable
You are creating PrepareStatement object at line number 212 but you are not assigning to the prepareStatement variable, which means prepareStatement variable still holds old object.
At line number 213 you are using setInt() method, it'll calls the old object. It seems your old object contains any place holders, because of the this reason you got Parameter index out of range exception.
Assign the newly created PreparedStatement object to prepareStatement variable at line number 212 to resolve your problem.

Using SSIS 2012 package parameters for connection properties

I am trying to write ETL that collects data from many identical server into a central repository. What I'm trying to do is write one package with source address, user id and password as parameters and execute the package once per server to be copied.
Is this doable? How can I use parameters to create a source?
I meant to ask how to parametrize the connection manager (is that even a real word?), not where to store the connection parameters. The answer is simple:
Create package parameters for Server, Database, User ID and Password
Create a connection manager as part of defining a data flow component
once a connection is defined, right-click on the connection manager at the bottom of the package design screen and select "Parametrize".
Select "ServerName" in the property drop-down
Select "Use existing parameter" or create new parameter if skipped step 1
If using existing parameter, select it from the drop down
Click OK to save (gotta do it after each parameter)
Repeat steps 4-7 for the rest of the parameters
You can store parameters in a table. Query the table with a sql task and store the results in a object variable. You can then use this variable in a for loop. Use expressions in SSIS to change values of your connection during each loop iteration.
Several books outline this method. Here is a code example.
Here are some steps - hopefully I didn't miss anything. You mention a server "Address", but I'm not sure exactly what you are trying to do. This example queries multiple sql servers.
You create the variables, SQL_RS with type of object, SRV_Conn with type of string. This holds my servername. In the execute SQL task, I have a query which returns the names of sql servers I want to query. Then set the following properties:
SELECT RTRIM(Server) AS servername
FROM ServerList_SSIS
WHERE (Server IS NOT NULL)
and coalesce(exclude,'0') <> 'True'
and IsOracle is Null
Execute SQL Task > General > ResultSet = "Full Result Set"
Execute SQL Task > Result Set Tab "Result Set Name = 0", Variable Name = "User::SQL_RS"
So we have a list of server names in the SQL_RS variable now.
ForEach > Collection > Enumerator = "Foreach ADO Enumerator"
ForEach > Collection > Enumerator Configuration > ADO Object source Variable = User::SQL_RS
This maps the first column of the SQL_RS object to the SRV_Conn variable, so each iteration of the loop will result in a new value in this variable.
ForEach > Variable Mappings > Variable = User::SRV_Conn, Index = 0
Inside the ForEach are some other sql execs, performing queries on sql databases, so I need to change the ServerName of my 'MultiServer' connection. I have another connection for the initial query that got me the list of servers to query. Making the connection dynamic is done in properties of the connection - right-click the connection > properties. Click the ellipses to the right of the expressions.
Connection > Properties > Expressions > Property = ServerName, Expression = "#[User::SRV_Conn]"
Note: The index value of 0 for the variable mapping works for Native OLEDB\SQL Server Native Client. If you're using another db provider, you may need to use other index types - this makes setup more confusing.
OLEDB = 0,1
ADO.NET = #Varname
ADO = #Param1, Param2
ODBC = 1,2
Full listing here.

How to set sql_mode hibernate

Is there a way to set the sql_mode (for MySql database) in Hibernate properties or in connection string?
Thanks,
Stefano
Yes, as documented sessionVariables property which is defined as follows can be used in JDBC connection string:
A comma-separated list of name/value pairs to be sent as SET SESSION
... to the server when the driver connects.
List of values goes inside single quotes:
sessionVariables=sql_mode='ALLOW_INVALID_DATES,NO_BACKSLASH_ESCAPES'