Every DBA of the mysql stored procedure needs to master. The following describes examples of java operations on the mysql stored procedure. If you are interested in the mysql stored procedure, take a look.
1. Create a table named test
- create table test(
- field1 int not null
- )
- TYPE=MyISAM ;
- insert into test(field1) values(1);
2. delete an existing Stored Procedure
-- Delete the Stored Procedure
Delimiter // -- Define the end symbol
Drop procedure p_test ;//
3. mysql Stored Procedure Definition
- create procedure p_test()
- begin
- declare temp int;
- set temp = 0;
- update test set field1 =temp;
- end
- //
4. Call Method
- call p_test();
- import java.sql.*;
-
- public class Test Conn{
-
- private Connection getConn(){
- Connection conn = null;
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- try {
- conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&
- characterEncoding=GBK","root","ntsky");
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return conn;
- }
-
- public void testC() {
- Connection conn = getConn();
- ResultSet rs = null;
- CallableStatement cs = null;
- String a = null;
- try {
- CallableStatement cStmt = conn.prepareCall("{call p_test()}");
- cStmt.executeUpdate();
- } catch (Exception e) {
- System.out.println("hahad" + e.getMessage());
- } finally {
- try {
- conn.close();
- } catch (Exception ex) {
- System.out.println("ex : " + ex.getMessage());
- }
- }
-
- }
-
- public static void main(String[] args) {
- new TestConn().testC();
- }
- }
The preceding example describes how to use java to operate mysql stored procedures.
Create MySQL trigger syntax
How to configure connection to multiple mysql servers
Use of mysql benchmark Function
MySQL clears the space at the beginning and end of a string.
Use of the concat_ws function in MySQL