另外,我的linux是redhat7.2的,mysql是3。23。41的
解决方案 »
- s2sh整合问题:Exception starting filter lazyLoadingFilter
- B/S模式中怎么实现即时消息提示。 难道用Ajax不停的请求后天。这样就会增加服务器的压力。是不是用socket实现。。怎么实现,有没人知道。谢谢
- 求解决方法!!
- 关于ajax + jsp 的一个问题(在线等候)请各位高手帮帮忙~!
- TCP新手关于TCP规范中的疑问
- 急寻 购物网站的架构用例图
- 找jsp编的简单计数器程序
- 想在下载时控制下载速度,怎么办?
- 救命啊!!!!
- 请问谁有jbuilder6企业版的注册码??
- 请问:刷新当前页面,有什么语句?
- 紧急求助:数据集更新问题,rs.updateInt("tag",1)
throw new SQLException(e.toString());
改为
throw new Exception(e.toString());或者catch (Exception e)
改为catch(SQLException e)
throw new SQLException(e.toString());
Connect.java:50:error:Exception "java.sql.InstantiationException"
is not catched and does not appear in throws list [JLS 8.4.4]
我看见一些代码例子中的下面这句:
Class.forName("com.mysql.jdbc.Driver").newInstance();
没有“.newInstance()”,是不是这里有问题?不过有的例子又有,什么原
因呢?
的com.mysql.jdbc.Driver改为"mm.。"就好像可以了。
难道mysql太老?
{
// System.err.println ("Cannot connect to database server");
throw new Exception(e.toString());
}系统反馈什么你再告诉我。
Connect.java:58:error:Exception "java.lang.Exception"
is not catched and does not appear in throws list [JLS 8.4.4]
正是琢磨不定,是不是还要import什么???
public static void main (String[] args)
...
catch (Exception e)
{
// System.err.println ("Cannot connect to database server");
throw new Exception(e.toString());
}
...
如果想跑出,至少在方法头中作如下处理:
public static void main (String[] args) throws Exception{
...
(我用的org.gjt.mm.mysql.Driver与你的驱动程序不一样,不过我已经试通了!)
import java.lang.*;
import java.sql.*;public class Connect
{
public static void main (String[] args)
{
Connection conn = null; try
{
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/tryjava";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)//这样测试把一切错误都捕捉并进行处理了
{
System.err.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}