public
Created

MySQL stored procedure with UTF-8 parameters and a JDBC client

  • Download Gist
Test.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import java.sql.*;
class Test {
public static void main(String [] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/test?characterEncoding=utf8", "user", "pass");
Statement s = conn.createStatement();
s.execute("call hello('겠겠지만');");
ResultSet rs = s.getResultSet();
rs.next();
System.out.println(rs.getString(1));
s.close();
conn.close();
}
}
hello.sql
SQL
1 2 3 4
CREATE PROCEDURE hello(str varchar(20) character set utf8)
BEGIN
select concat('Hello ', str);
END

Great, really helped. I am using org.springframework.jdbc.core classes rather than java.sql - must be the version of the driver spring is using...

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.