首先说明,数据库连接地址用户名都是对的! 就是老是抛出异常?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");
}
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");
}
解决方案 »
- iReport 分组报表
- hibernate3.3+oracle11g的连接问题求解各位高手
- 简单的JS的问题。
- 我写好项目保存时。提示我修改的类拒接访问
- Tomcat No Java Virtual Machine found的问题
- 600分,关于Sun Application Server的jms访问!
- 求学若渴,学习java开发两年了,工作也将近两年了,从事的是java web开发,求大神推荐几本好的书籍
- 各位,一对多的关系,用hibernate查出来后在struts中如何显示?
- RMI中的stub的问题?
- 我的web项目 在运行tomcat时候 报:Server ssm failed to start. 大神麻烦给我看看,谢谢各位大神
- 求助各位大虾,帮帮忙吧,郁闷啊
- 各位大侠帮助小弟一下:The value for the useBean class attribute test.SayHi is invalid.
url=jdbc:mysql://localhost:3306/mydata