2017-05-04 70 views
0

我設計了一個jsp頁面來檢查db連接。我正在使用xampp執行時收到錯誤消息。我在jsp中檢查db連接時收到錯誤消息


<%@ 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> 

回答

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> 
+0

此外,檢查您已經添加的MySQL連接器罐子的類路徑 –

+0

能否請你幫我設置DBConnection的 – Karthik

+0

添加MySQL連接器的Java類路徑的jar到LIB(WEB-INF-γ - > lib)文件夾 –

相關問題