How to call mysql stored procedures in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Radhakrishnans
    New Member
    • Sep 2006
    • 5

    #1

    How to call mysql stored procedures in java

    hai friends
    i am new to java and mysql.i have created stored procedures in mysql.Now i want to call that stored procedures in java.All works fine.but it show the following error.

    unreported exception java.lang.Insta ntiationExcepti on; must be caught or declared to be thrown
    Class.forName ("com.mysql.jdb c.Driver").newI nstance();
    I need code sample along with connection string.please.. ..

    My codings here

    CallableStateme nt proc = null;


    try
    {
    String url = "jdbc:mysql ://localhost/Test_DB";
    Class.forName ("com.mysql.jdb c.Driver").newI nstance();
    Connection conn = DriverManager.g etConnection (url, "root", "");

    proc = conn.prepareCal l("{ call sp_InsertEmploy ee('"+EmployeeC ode+"','"+Emplo yeeName+"','"+D esignation+"', '"+Department+" ') }");
    proc.execute();
    proc.close();
    conn.close();
    }
    catch (SQLException e)
    {

    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Radhakrishnans
    hai friends
    i am new to java and mysql.i have created stored procedures in mysql.Now i want to call that stored procedures in java.All works fine.but it show the following error.

    unreported exception java.lang.Insta ntiationExcepti on; must be caught or declared to be thrown
    Class.forName ("com.mysql.jdb c.Driver").newI nstance();
    I need code sample along with connection string.please.. ..

    My codings here

    CallableStateme nt proc = null;


    try
    {
    String url = "jdbc:mysql ://localhost/Test_DB";
    Class.forName ("com.mysql.jdb c.Driver").newI nstance();
    Connection conn = DriverManager.g etConnection (url, "root", "");

    proc = conn.prepareCal l("{ call sp_InsertEmploy ee('"+EmployeeC ode+"','"+Emplo yeeName+"','"+D esignation+"', '"+Department+" ') }");
    proc.execute();
    proc.close();
    conn.close();
    }
    catch (SQLException e)
    {

    }
    what happens when you add the catch InstantiateExce ption block near the SQLException?
    Note when catching exceptions try do something not to leave the catch block blank. It makes it easier to debug

    Comment

    Working...