By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,012 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,012 IT Pros & Developers. It's quick & easy.

How to call mysql stored procedures in java

P: 5
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.InstantiationException; must be caught or declared to be thrown
Class.forName ("com.mysql.jdbc.Driver").newInstance();
I need code sample along with connection string.please....

My codings here

CallableStatement proc = null;


try
{
String url = "jdbc:mysql://localhost/Test_DB";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection (url, "root", "");

proc = conn.prepareCall("{ call sp_InsertEmployee('"+EmployeeCode+"','"+EmployeeNa me+"','"+Designation+"', '"+Department+"') }");
proc.execute();
proc.close();
conn.close();
}
catch (SQLException e)
{

}
Sep 28 '06 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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.InstantiationException; must be caught or declared to be thrown
Class.forName ("com.mysql.jdbc.Driver").newInstance();
I need code sample along with connection string.please....

My codings here

CallableStatement proc = null;


try
{
String url = "jdbc:mysql://localhost/Test_DB";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection (url, "root", "");

proc = conn.prepareCall("{ call sp_InsertEmployee('"+EmployeeCode+"','"+EmployeeNa me+"','"+Designation+"', '"+Department+"') }");
proc.execute();
proc.close();
conn.close();
}
catch (SQLException e)
{

}
what happens when you add the catch InstantiateException block near the SQLException?
Note when catching exceptions try do something not to leave the catch block blank. It makes it easier to debug
Sep 28 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.