How to run SQL(MYSQL) stored procedure in JAVA jdbc? -


I am a MySQL user and I am using the following statement in the MySQL workspace: (Based on these statements)

/ P> SET group_concat_max_len = 4294967295; SELECT GROUP_CONCAT ('SELECT', QUOTE (COLUMN_NAME), 'FROM (choose * from table_name * s3_01 =', coloumn1, '' 'abc', 'WHERE', REPLACE (COLUMN_NAME, '`', '` `') Not Faucet, 'Hosting COUNT (*)' SEPARATOR Union All ') Information from INTO @sql_SCAMA Columns where TabCHAMA = Database () and Tableinda = 'Table_Name'; Prepare SSML with SSMT; EXTUTE STMT; DEALLOCATE STMT;

Although it works in my workspace, I do not know how it works in Java. For example, I created the following code:

  string sql1 = "SET group_concat_max_len = 4294967295;"; String sql2 = "SELECT GROUP_CONCAT ('SELECT', QUOTE (COLUMN_NAME), 'FROM (select * from PTC_weight) where S3_01 =', column 1, '' ABC '', 'WHERE', repeat (COLUMN_NAME, '`' '' '),' 'Not False' ',' Hosting COUNT (*) 'SEPARATOR Union All') from INTO @sql Informatics. Columns where TabCCHA = Database () and Table_ NAME = 'ptc_weight'; "; String sql3 = "STMT from FSM SSL;"; String sql4 = "extract stat;"; String sql5 = "DELLOCATE stmt;"; String [] results = getcent (sql1 + sql2 + sql3 + sql4 + sql5); Public fixed string [] [] getResult (string SQL) {System.out.println (sql); Connection Con = Null; Prepared place PS = null; Results set rs = null; String [] [] resulttable = null; Try {con = getCon (); Ps = con.prepareStatement (SQL); Rs = ps.executeQuery (); ResultsetMetaData result = rs.getMetaData (); Int rowNum = 0; // go to the last line rs.last (); RowNum = rs.getRow (); // Reset the row before replacing it to get the data. first. (First); Int colNum = result.getColumnCount (); Results tab = new string [row noam] [column]; For (int itr1 = 0; itr1 & lt; rowNum; itr1 ++) {rs.next (); For (int itr2 = 0; itr2 & lt; colNum; itr2 ++) {resultTable [itr1] [itr2] = rs.getObject (itr2 +1) .toString (); }}} Catches (Eclipse E) {// Tudo Auto-Generated Catch Block e.printStackTrace (); } Finally {DB Close (Conn, PA, RS); } / / Finally resulted in results; }  

However, this does not work, I think I have created a wrong code for the use of stored procedure, but I have no idea to deal with this problem.

  callable statement column statement = empty; String getDBUSERByUserIdSql = "{getDBUSERByUserId call (?,?,?,?)}" Callable Stats.Contents (1, 10); CallBattle Stateat Registry AutoPamator (2, Java SQL Type VARCHAR); CallBattle Stateat Registry AutoPamator (3, Java SQL Type VARCHAR); CallBattle Stateat Registry AutoPamator (4, Java SQL, TypeDidet); // execute getDBUSERByUserId store process callableStatement.executeUpdate (); String Username = Callable Statement.getString (2); String created = callable. Statement.getString (3); Date created date = callable settings. GateDet (4); System.out.println ("username:" + username); System.out.println ("Created:" + created); System.out.println ("Created Date:" + Created Date);  

You can modify your code as simple as you need with less logic and with resultset

.

  CallableStatement cstmt = con.prepareCall ("{getEmployeeDetails phone (?,?)}"); Cstmt.setInt ("employee id", 123); Cstmt.setInt ("Company ID", 456); Results reset rs = cstmt.executeQuery ();  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -