| 1 | <%@ page import="java.io.*, java.util.*, javax.servlet.*, java.sql.*" %> |
| 2 | <% |
| 3 | |
| 4 | Connection connection = null; |
| 5 | try { |
| 6 | String connectionURL = "jdbc:mysql://localhost/MyBd?useUnicode=yes&characterEncoding=UTF-8"; |
| 7 | Class.forName("com.mysql.jdbc.Driver").newInstance(); |
| 8 | connection = DriverManager.getConnection(connectionURL, "MyBd", "MyBd"); |
| 9 | if(!connection.isClosed()) |
| 10 | out.println("Successfully connected to " + connectionURL + " MySQL server using TCP/IP"); |
| 11 | } catch (Exception e){ |
| 12 | out.println("Unable to connect to database: " + e); |
| 13 | } |
| 14 | finally { |
| 15 | if (connection != null) |
| 16 | connection.close(); |
| 17 | } |
| 18 | |
| 19 | %> |