所有需要异常处理(public "returntype" methodName() throws XXXXException)的方法在调用时需要你进行异常处理。简单说:把getConnection()和createStatement()等等这些东西放到一个try{}catch(){}块中
解决方案 »
- 关于mysql查询问题
- mysql中配置文件my-innodb-heavy-4G.ini选择
- C程序设置MYSQL编码为UCS2和UTF8怎么就不行呢?用GBK或GB2312就可以!
- 求SQL语句
- postgres数据库编码问题
- mysql中关于TEXT类型的中文模糊查询问题
- postgresql数据库又类似phpadmin的数据管理软件吗?
- 版主,insert into后的事情。。。。
- 考试成绩排名问题求助
- mysql 里面where条件直接使用变量的问题
- 在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());
}