这段连接数据库的代码为什么会有SQLException异常?
import java.sql.*;
public class MakingAConnection{
public static void main(String[] arg){
try{
Class.forName("COM.cloudscape.core.JDBCDriver");
String sourceURL=new String("jdbc:cloudscape:../database/Wrox4370DB");
Connection databaseConnection=DriverManager.getConnection(sourceURL);
//System.out.println("Successfully connected!!");
Statement statement=databaseConnection.createStatement();
ResultSet artistNames=statement.executeQuery("SELECT artistid,artistname "+
"FROM artistsandperformers");
while (artistNames.next())
{
System.out.println(artistNames.getInt("artistid")+" "+
artistNames.getString("artistname"));
databaseConnection.close();
}
}
catch (ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch (SQLException sqle)
{
System.err.println(sqle);
}
}
}
下面是解译:
H:\begjavadb\MakingAConnection>javac MakingAConnection.java
H:\begjavadb\MakingAConnection>java MakingAConnection
This copy of Cloudscape is licensed for DEVELOPMENT ONLY.
It is a violation of the license agreement to deploy this version in a productio
n application.
For information about licensing Cloudscape for application deployment,
contact cloud-sales@informix.com or call 888/595-2821 ext. 7664.
Additional licensing information can be found at
http://www.cloudscape.com/licensing.
Successfully connected!!
100 10,000 Maniacs
SQL Exception: No current connection.
问题点数:20、回复次数:3Top
1 楼nobody_am(小兵)回复于 2002-11-09 14:34:21 得分 0
上面的 No current connection是什么意思?Top
2 楼namowen(寒号不已)回复于 2002-11-09 14:52:34 得分 20
databaseConnection.close();
把这句去掉。Top
3 楼nobody_am(小兵)回复于 2002-11-09 15:01:51 得分 0
不错,找到了,不是去掉,而是放到while循环的外面。Top




