I'm a beginner of creating a stored procedure using JDBC and MariaDB. When I create the procedure, I get an error. I ran in to the problem since yesterday:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@auth_id varchar(15),@auth_fname varchar(20) output,@auth_lname varchar(20) o...' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
What I tried so far, I attached the code below. I don't know what causes the error.
public class Jdbcc {
Connection con;
PreparedStatement pst;
public Jdbcc()
{
Connect();
}
public void Connect()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/abclibrary", "root","");
String str = "CREATE PROCEDURE authors @auth_id varchar(15), @auth_fname varchar(20) output, @auth_lname varchar(20) output AS SELECT @auth_fname=auth_fname,@auth_lname= auth_lname FROM authors where auth_id=@auth_id";
Statement stmt = con.createStatement();
int k = stmt.executeUpdate(str);
System.out.println("Created.......");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[])
{
Jdbcc jk = new Jdbcc();
}
}