所有需要异常处理(public "returntype" methodName() throws XXXXException)的方法在调用时需要你进行异常处理。简单说:把getConnection()和createStatement()等等这些东西放到一个try{}catch(){}块中
解决方案 »
- 在线mysql数据库发现负载过高
- mysql c api 处理事务
- [求助]linux中mysqld进程占cpu99????
- postgres COPY 问题,谢谢.
- mysql administrator 这个软件中,怎么用sql语句建数据表.
- 谁有mysql的安装软件啊
- 在我的phpadmin中总有这句"使用链接表的额外特性尚未激活。要查出原因,请单击此处。"是什么意思呢?
- MySQL 占用太多资源
- 请教:Mysql中关闭数据库的命令是什么?
- 关于Mysql中外键foreign key
- 在Linux下用Kylix,连接Mysql,连接成功,用dbedit可以显示,但dbgrid为何不能用。
- 用apache-mysql-php4软件在win2kserver下配置支持php的环境问题?很急!希望能详细解答!
这是我以前的代码import java.sql.*;class db
{
String str;
Connection Conn;
Statement Stmt;
ResultSet RS ;
db(String sss)
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("Load driver.");
Conn = DriverManager.getConnection("jdbc:mysql://132.208.5.2/dbase?user=starnet");
System.out.println("connect to");
}
catch (Exception R)
{
System.err.println("Unable to load driver.");
R.printStackTrace();
}
}
public ResultSet txt(String sql)
{
try
{
Stmt = Conn.createStatement();
RS = Stmt.executeQuery(sql);
System.out.println(sql);
return RS;
}
catch (SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
return RS;
}
}
public void dbclose()
{
try
{
RS.close();
Stmt.close();
Conn.close();
}
catch (SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
}
}
还有
try
{
String ssst = new String("select tmport.p_id from tmport,office where office.o_idin=tmport.jh and office.o_idin="+idin);
ResultSet rs = ddd.txt(ssst);
while (rs.next())
{
coport.addItem(rs.getString(1));
System.out.println("port: "+rs.getString(1));
}
rs.close();
}
catch (SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}