数据库连接类DBConn.java
package com.wincom.struts.util;
import java.sql.*;
public class DBConn {
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/wincom";
String user = "root";
String pass = "root";
conn = DriverManager.getConnection(url,user,pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
------------------------------------------------------------------------------------------------
JSP测试页
<
%@page import="java.sql.*"%>
<
%@page import="com.wincom.struts.util.DBConn"%>
My JSP 'index.jsp' starting page 数据库连接成功!