no suitable driver

本文介绍了一种解决使用新的Microsoft JDBC驱动时出现的nosuitabledriver错误的方法。通过提供具体的代码示例,展示了如何正确配置连接字符串及加载驱动类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚装了M$新的jdbc驱动,就出了个no suitable driver错误.
做了个方案大家可以参考一下,除了和for 2000的字符串有一点不同外,用的Class有也不同,这个大家要注意

None.gifpackage com.cyberport.beans;
None.gif
None.gif
None.gif
import java.sql.*;
None.gif 
None.gif
ExpandedBlockStart.gifContractedBlock.gif
public class ConnectionDB dot.gif{
InBlock.gif
InBlock.gif    Connection con 
= null;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public ConnectionDB()dot.gif{
InBlock.gif        
ExpandedSubBlockEnd.gif    }

InBlock.gif     
InBlock.gif    
InBlock.gif    
public Connection getConnectionDB()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
InBlock.gif        String driverName 
= "com.microsoft.sqlserver.jdbc.SQLServerDriver"
InBlock.gif        String ConnectionString 
= "jdbc:sqlserver://local;database=YourDatabaseName;";
InBlock.gif        String userName 
=  "UserName";
InBlock.gif        String userPwd 
=   "PassWrod";
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
try dot.gif
InBlock.gif        Class.forName(driverName); 
InBlock.gif        con 
= DriverManager.getConnection(ConnectionString, userName, userPwd); 
InBlock.gif        
//System.out.println("Connection Successful!"); 
ExpandedSubBlockEnd.gif
        }
 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
catch (Exception e) dot.gif
InBlock.gif        e.printStackTrace(); 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif      
return con;
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/microtea/archive/2006/02/13/329626.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值