Created
June 12, 2012 16:56
-
-
Save joni/2918685 to your computer and use it in GitHub Desktop.
MySQL stored procedure with UTF-8 parameters and a JDBC client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE hello(str varchar(20) character set utf8) | |
BEGIN | |
select concat('Hello ', str); | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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...