java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;解决...

本文介绍了一种常见的Java通过JDBC连接SQLServer2008时出现的问题及其解决方案。主要问题为java.sql.SQLException: Nosuitabledriverfoundfor jdbc:microsoft:sqlserver。解决方法在于调整连接字符串,去除不适用于SQLServer2008的'microsoft'前缀。

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

环境:SQLServer 2008 R2 + MyEclipse 6.5 + JDK 1.6.24

问题:Java通过JDBC连接SQLServer 2008,出现如下问题:ava.sql.SQLException: No suitable driver found forjdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=QQ。

解决:检查连接数据库时写的代码是否有问题。

代码如下:


package com.qq.client.db;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 连接数据库的类
 * @since 1.0
 * @author Wentasy
 *
 */
public class ConnDB {
	private Connection conn = null;
	
	public Connection getConn(){
		try {
			//注意这串字符串的顺序,不同的数据库版本这行不同。
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			//conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=QQ","sa","sa");
			//注:连接SQLServer 2008 没有microsoft,把这个去掉问题解决。
			conn = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=QQ","sa","sa");

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return conn;
	}
}



参考资料:

http://stackoverflow.com/questions/5616898/java-sql-sqlexception-no-suitable-driver-found-for-jdbcmicrosoftsqlserver

附JDBC连接SQLServer 2008驱动下载,请点击这里


Exception in thread "main" java.lang.RuntimeException: 创建IDatabaseQuery实例出现错误: at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.<init>(ConfigBuilder.java:111) at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:171) at com.baomidou.mybatisplus.generator.FastAutoGenerator.execute(FastAutoGenerator.java:229) at com.wangke.hyruleadmin.CodeGenerator.main(CodeGenerator.java:38) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.<init>(ConfigBuilder.java:109) ... 3 more Caused by: java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/hyrule at com.baomidou.mybatisplus.generator.config.DataSourceConfig.getConn(DataSourceConfig.java:243) at com.baomidou.mybatisplus.generator.query.DefaultQuery.<init>(DefaultQuery.java:57) ... 8 more Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/hyrule at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:208) at com.baomidou.mybatisplus.generator.config.DataSourceConfig.getConn(DataSourceConfig.java:238) ... 9 more 以上是报错信息,下面是源代码FastAutoGenerator.create("jdbc:mysql://localhost:3306/hyrule", "root", "1234") .globalConfig(builder -> { builder.author("202508wang") // 设置作者 // .enableSwagger() // 开启 swagger 模式 // .fileOverride() // 覆盖已生成文件 .outputDir("E:\\IdeaProjects\\hyrule-admin\\src\\main\\java"); // 指定输出目录 }) .packageConfig(builder -> { builder.parent("com.wang") // 设置父包名 .moduleName(moduleName) // 设置父包模块名 .pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation)); // 设置mapperXml生成路径 }) .strategyConfig(builder -> { builder.addInclude(tables) // 设置需要生成的表名 .addTablePrefix("x_"); // 设置过滤表前缀 }) .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板 .execute(); }
最新发布
08-10
linx启动nacos报错025-03-15 15:13:22,942 WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'namespaceControllerV2' defined in URL [jar:file:/soft/tar/nacos/target/nacos-server.jar!/BOOT-INF/classes!/com/alibaba/nacos/console/controller/v2/NamespaceControllerV2.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'namespaceOperationService' defined in URL [jar:file:/soft/tar/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-core-2.3.2.jar!/com/alibaba/nacos/core/service/NamespaceOperationService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalOtherPersistServiceImpl' defined in URL [jar:file:/soft/tar/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-core-2.3.2.jar!/com/alibaba/nacos/core/namespace/repository/ExternalNamespacePersistServiceImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.nacos.core.namespace.repository.ExternalNamespacePersistServiceImpl]: Constructor threw exception; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值