【www.gdgbn.com--mysql教程】

asp教程.net c# java调用mysql教程存储过程方法
本文章主要介绍三种asp.net教程 c# java调用mysql存储过程方法,一一举例说明了关于如何创建如调用mysql存储过程的方法哦。

简单存储过程

 
create procedure `deletedb`(in m_orgid char(12))
begin
        delete from hardwareinfo where orgid=m_orgid;
        delete from addressinfo where orgid=m_orgid;      
end


aspx.net

public void delete_procedure()  //"删除"的存储过程
     {
        string str_orgid = client_str;  //获得orgid
        string myconn_str = webconfigurationmanager.connectionstrings["mysqlconnectionstring"].connectionstring;
         mysqlconnection myconn = new mysqlconnection(myconn_str);
         mysqlcommand mycomm = new mysqlcommand("deletedb", myconn);//(client_str);
        //mycomm.connection = myconn;
        try
         {
             mycomm.connection.open();
             mycomm.commandtype = commandtype.storedprocedure;
             mysqlparameter myparameter;
             myparameter = new mysqlparameter("?m_orgid", mysqldbtype.string);
             myparameter.value = str_orgid;
             myparameter.direction = parameterdirection.input;
             mycomm.parameters.add(myparameter);

            //mycomm.commandtext = "deletedb"; //存储过程名
            //mycomm.parameters.add("m_orgid", str_orgid);
             mycomm.executenonquery();
         }
        catch
         {
             mycomm.connection.close();
             mycomm.dispose();
         }
        finally
         {
             mycomm.connection.close();
             mycomm.dispose();
         }
     }

     

 

c#

if(!mysql_init(&mysql))
       {
              printf("mysql_init failed!n");
              return 0;
       }
连接到mysql
//login or connect
       if(!mysql_real_connect(&mysql,"localhost","root","","billingdb",0,null,client_multi_statements))
       {
              printf("mysql_real_connect() failed!n");
              mysql_close(&mysql);
              return 0;
       }
调用存储过程
       //call
       strcpy(query,"call querystudent (1,@ret,@ out_name,@ out_age)");
       printf("query sql=[%s]n",query);
    ret= mysql_real_query(&mysql,query,(unsigned int)strlen(query));


java

package kissjava.sql;
import java.sql.callablestatement;
import java.sql.connection;
import java.sql.drivermanager;
import java.sql.sqlexception;
import java.sql.types;
public class sqlutils {
    string url = "jdbc:mysql://127.0.0.1:3306/userinfo";
    string username = "root";
    string password = "zhui007";
    public connection getconnection() {
        connection con=null;
        try{
            drivermanager.registerdriver(new com.mysql.jdbc.driver());
            con = drivermanager.getconnection(url, this.username, this.password);
        }catch(sqlexception sw){
         }
        return con;
    }
    public void testproc(){
        connection conn = getconnection();
        callablestatement stmt = null;
        try{
            stmt = conn.preparecall("{call mappingproc(?)}");   
            stmt.registeroutparameter(1, types.integer);
            stmt.execute();
            int i= stmt.getint(1);
            system.out.println("count = " + i);
        }catch(exception e){
            system.out.println("hahad = "+e.tostring());
        }finally{
            try {
                stmt.close();
                conn.close();
            }catch (exception ex) {
                system.out.println("ex : "+ ex.getmessage());
            }
        }
    }
    public static void main(string[] args) {
        new sqlutils().testproc();
    }
}

本文来源:http://www.gdgbn.com/shujuku/27638/