首先说明,数据库连接地址用户名都是对的! 就是老是抛出异常?mysqlCon.java:package Demo;
import java.sql.*;
public class mysqlCon {
  private final String uName="root";
private final String uPwd="gaoshuai";
private final String db="tree";
private String url="http://localhost:3306/"+db;
private final String driver="com.mysql.jdbc.Driver";
public  ResultSet rs=null;
private Statement st=null;
private Connection con=null;
public  mysqlCon()
{
try
{
Class.forName(this.driver);
con=DriverManager.getConnection(this.url,this.uName,this.uPwd);
st=con.createStatement();
}catch(Exception e)
{
e.printStackTrace(); 
}finally
{
try
{
if(con!=null)
con.close(); 
if(st!=null)
st.close();
if(rs!=null)
rs.close();
}catch(Exception e)
{
e.printStackTrace();
}
}

}
public ResultSet exQuery(String sql) 
{
return this.st.executeQuery(sql);
}
}
异常:
java.lang.Error: Unresolved compilation problem: 
Unhandled exception type SQLException Demo.mysqlCon.exQuery(mysqlCon.java:41)
Demo.servletMysql.doGet(servletMysql.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
调用方式:
   在servlet里面调用 的
import java.sql.*;
import Demo.mysqlCon;public void doGet(HttpServletRequest request, HttpServletResponse response)
{
                   mysqlCon db=new mysqlCon();
ResultSet getRs=db.exQuery("select  name from tree where fid=0");
}