奇怪的数据库问题!急!!!

kunzhong 2006-04-03 11:01:54
大家好:现在我在jb里面的Tools-->Database Pilot测试的是好的
就是说是可以连接上的
我的driver是:Driver class:com.microsoft.jdbc.sqlserver.SQLServerDriver
Simple URL:microsoft:sqlserver://localhost:1433;DatabaseName=mybase
但是为什么在jb里面运行就是不可以呢?奇怪?
他总是出现
Message:No suitable driver
SQLState:08001
ErrorCode:0
说我没有合适的驱动!那但是为什么又可以连接上呢?
代码如下:
void jButton1_actionPerformed(ActionEvent e) {
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="microsoft:sqlserver://image:1433;DatabaseName=students;User=sa;Password=sa";
connection=DriverManager.getConnection(url);
statement=connection.createStatement();
String sql="select * from yd";
rSet=statement.executeQuery(sql);
ResultSetMetaData data=rSet.getMetaData();
int col=data.getColumnCount();
for(int i=1;i<=col;i++){
if(i<col){
System.out.print(data.getCatalogName(i)+" " );
}
else{
System.out.println(data.getCatalogName(i) );
}
}
while(rSet.next()){
for(int i=1;i<=col;i++){
if(i<col){
System.out.print(rSet.getString(i) + " " );
}
else{
System.out.println(rSet.getString(i) ) ;
}
}
}
rSet.close();

}catch(SQLException ex){
while(ex!=null){
System.out.println("Message:"+ex.getMessage() );
System.out.println("SQLState:"+ex.getSQLState());
System.out.println("ErrorCode:"+ex.getErrorCode());
ex=ex.getNextException();
}
}
catch(Exception ex){
ex.printStackTrace();
}
finally{
try {
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
}
catch (SQLException ex) {

System.out.println("Message:" + ex.getMessage());
System.out.println("SQLState:" + ex.getSQLState());
System.out.println("ErrorCode:" + ex.getErrorCode());

}
}

}
...全文
104 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxmvip 2006-04-24
  • 打赏
  • 举报
回复
class.forname
Nuage 2006-04-04
  • 打赏
  • 举报
回复
楼上正解!
zx2002027 2006-04-03
  • 打赏
  • 举报
回复
String url="microsoft:sqlserver://image:1433;DatabaseName=students;User=sa;Password=sa";
connection=DriverManager.getConnection(url);
改成
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=students";
connection=DriverManager.getConnection(url,"sa","sa");
另外请确认connection等是声明的实例

62,624

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧