mysql stored procedure with iBatis - ibatis

My application used Spring MVC+iBatis+JBoss7+MySQL. I have a stored procedure in mySQL, mapped it in my iBatis mapper.xml file and calling it via my sqlMapClient from my DAO.
If i execute the dao method once it works fine, but if i execute two calls to the same method with different stored procedure parameters(change in parameter means change in the result columns in my stored procedure), I get an exception that says my sql gramer is wrong. Looking at the logs i find that iBatis is trying to map my first query columns (result of my initial method call) to my result map. I even tried printing the hashcode of my dao class instance and they are different. Why is this happening when the procedure executes just fine when tried from DB clients like DbVislaulizer
For information I am using a HashMap as my resultclass in my mapper.xml. This returns me a list of linkedhashmaps in my dao..
Any help would be really handy.
Thanks in advance

Fixed it. Have to set the property remapResults="true" in mapper.xml
Eg
select id="myReport" parameterClass="Map" resultClass="java.util.LinkedHashMap" remapResults="true"

Related

How to pass dynamic parametrs to query in MS Power BI?

I need to build a report in Power BI. I can get the data for the report by calling the MS SQL Server stored procedure with parameters. Question: How can I pass dynamic parameters from a report to a stored procedure call? And the second question: one of the parameters is the user login. How to get it in Power BI and transfer the stored procedure call parameter to?
Go to query editor, and create the required parameters (from manage parameters)
Now create a new query that calls SQL procedure, you can pass hardcoded parameters for now.
Once data are imported, go to advance editor and replace the hard-coded parameter in the query part with the parameter you created, you will have to concat it.
refer: https://www.c-sharpcorner.com/article/execute-sql-server-stored-procedure-with-user-parameter-in-power-bi/

Python mssql passing procedure user defined data type as parameter

My original purpose was to bulk insert into my db
I tried pyodbc, sqlalchemy and ceodbc to do this with executemany function but my dba checked and they execute each row individually.
his solution was to run procedure that recieve table (user defined data type) as parameter and load it into the real table.
The problem is no library seem to support that (or at least no example on the internet).
So my question is anyone try bulk insert before or know how to pass user data defined type to stored procedure?
EDIT
I also tried bulk insert query but the problem it requires local path or share and it will not happend because organizition limits
Sqlalchemy bulk operations doesn't really inserts a bulk. It's written in the docs.
And we've checked it with our dba.
Thank you we'll try the xml.

Temporary Table vs. Table Variable - both don't work

I use SQL Server and Linq-to-SQL in my application.
I have to do a lot of database stuff and after a few hours work I have a stored procedure ready to run.
Sadly I use temporary tables in it (#TempTable) so Linq-to-SQL will give me an error for my return type (read about this e.g. here: LINQ "The return types for the following stored procedures could not be detected" (NOT temp tables)).
The only working solution for me is to switch to a table variable (DECLARE #temptable table) - but for this I found out it is not possible to use dynamic queries (which I do around 60% of my whole stored procedure).
Any ideas?
i found a solution to my problem: I simply wrap my first Stored Procedure with temporary tables in a second Stored Procedure with a single select.
This is automaticly recognized with an auto genereated object in LinQ and I'm happy :)

SQL DMO based code generator

I already have a code generator based on SQL DMO, that writes the a C# function for any stored procedure in by SQL Server 2008 database. Currenly however the code generator can only handle stored procedures that have input and output parameters. For stored procedures that return multiple records, the code generator returns a datatable with rows that each represent a output record.
Is there a way using SQL DMO to determine the fields that would be returned by a stored procedure if the output of a stored procedure is select * from Member where MemberID=1?
Thanks
My guess is that you cannot do this in DMO, since DMO relies on meta information stored in SQL Server, and the result set description of an SP is not stored in that way (as far as I know).
What you can do, however, is to have your generator execute the stored procedure inside a transaction, and analyze the resulting SqlDataReader. Have a look at the GetName(), GetFieldType() and GetSchemaTable() methods to construct your result class.
After execution, rollback the transaction (in case the SP makes any changes to the database).
You also might consider upgrading your generator to SMO, as MSDN states that DMO will not be supported in the future.

How to refactor T-SQL stored procedure encapsulating it's parameters to a class

On my SQL Server 2008 I have a stored procedure with a large number of parameters.
The first part of them is used in every call and parameters from the second part are used rarely. And I can't move the logic to two different stored procedures.
Is there a way to encapsulate all this parameters to a class or struct and pass it as a stored procedure parameter?
Can I use SQL CLR. Are there other ways?
Have you tried Table Valued Parameters?
Actually, I wont use CLR function for anything which can be done effectively and easily in t-SQL. For example, last time I used CLR function is for updating a column based on some complex regex which I found pretty hard to do in t-SQL.
It sounds like your concern is with the need to specify values for each parameter. Would it work for you to just assign default values to the parameters that aren't used as often (so you don't need to pass every parameter each time the proc is called)?
A CLR type could be an option (as could XML) but I'm not sure it would be a good idea to go down that route.
If the volume of parameters is causing you problems in your application you could try one of the following two methods:
1) pass in a single parameter of XML data type that contains all of the parameters data. you could then parse out what you need. See xml (Transact-SQL).
2) create a table parameter, see Table-Valued Parameters (Database Engine), where the table is:
ParameterName sysname
DataValue sql_variant
With either of these methods, you'd more than likely need to expand them out into local variables to use them again.

Resources