<%@ 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();
}
%>