Finish exo9 code and fix unicode support where possible.
[TD_webapps.git] / ROOT / exo9 / connectJspMysql.jsp
index 5428f7a6845d7d044c70c2bc83fff843902a1805..8ce40ed9faca33a3a97bdf9956fcec6240826ca3 100644 (file)
@@ -1,16 +1,19 @@
 <%@ page import="java.io.*, java.util.*, javax.servlet.*, java.sql.*" %>
 <%
 
+Connection connection = null;
 try {
-    String connectionURL = "jdbc:mysql://localhost/MyBd";
-    Connection connection = null;
+    String connectionURL = "jdbc:mysql://localhost/MyBd?useUnicode=yes&characterEncoding=UTF-8";
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     connection = DriverManager.getConnection(connectionURL, "MyBd", "MyBd");
     if(!connection.isClosed())
         out.println("Successfully connected to " + connectionURL + " MySQL server using TCP/IP");
-    connection.close();
     } catch (Exception e){
-            out.println("Unable to connect to database: " + e);
+        out.println("Unable to connect to database: " + e);
+    }
+    finally {
+        if (connection != null)
+            connection.close();
     }
 
 %>