LZ,您确定要在struts2中的action中连接数据库。本人推荐用HIbernate连接数据库。用jabc去连接数据库Mysql的话可以用下面的代码
public
static Connection getConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection conn=null;
try {
conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/user?useEncode=true&characterEncoding=utf-8","root","root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
仅供参考啊。