我在jsp中检查数据库连接时收到错误消息

时间:2017-05-04 20:46:29

标签: jsp

我设计了一个jsp页面来检查数据库连接。我正在使用xampp我在执行时收到错误消息。

<%@ page import="java.sql.*"%>
<html>
<head></head>
<body>
<% 
  String url="jdbc:mysql://localhost3306//MariaDB";
  Connection con;
   try
    {
       Class.forName("com.mysql.jdbc.Driver");
       con=DriverManager.getConnection(url,"root","");//connect with xampp
    }
 catch(Exception e)
   {
         out.println("error");
    } 
 %>



</body>
</html>

1 个答案:

答案 0 :(得分:0)

<%@ page import="java.sql.*"%>
<html>
<head></head>
<body>
<% 
  String url="jdbc:mysql://localhost:3306//MariaDB"; //Missing colon(:) between localhost and port number
  Connection con;
   try
    {
       Class.forName("com.mysql.jdbc.Driver");
       con=DriverManager.getConnection(url,"root","");//connect with xampp
    }
 catch(Exception e)
   {
         e.printStackTrace(); //add this line So you can find root cause of error
         out.println("error");
    } 
 %>



</body>
</html>