X-Git-Url: https://git.piment-noir.org/?p=TD_webapps.git;a=blobdiff_plain;f=ROOT%2Fexo9%2FconnectJspMysql.jsp;fp=ROOT%2Fexo9%2FconnectJspMysql.jsp;h=8ce40ed9faca33a3a97bdf9956fcec6240826ca3;hp=5428f7a6845d7d044c70c2bc83fff843902a1805;hb=d2793705bda98fb61daa7811d9607f5002c2595e;hpb=714e1b9156a383581be324ae0792e6e0767a7106 diff --git a/ROOT/exo9/connectJspMysql.jsp b/ROOT/exo9/connectJspMysql.jsp index 5428f7a..8ce40ed 100644 --- a/ROOT/exo9/connectJspMysql.jsp +++ b/ROOT/exo9/connectJspMysql.jsp @@ -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(); } %>