JAVA报错no suitable driver

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA报错no suitable driver相关的知识,希望对你有一定的参考价值。

我已经装驱动啦..
public class Demo
public void main(String[] args) throws Exception
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/lisa";
Class.forName(driver);
Connection con = DriverManager.getConnection(url, "root", "1234");
Statement cmd = con.createStatement();
String sql = "select uid,uname from users";
ResultSet rs = cmd.executeQuery(sql);
while (rs.next())
int uid = rs.getInt("uid");
String uname = re.getString(2);
String usex =re.getString(3);
int uphone =re.getInt(4);
String uaddress =re.getString(5);
String uemail =re.getString(6);
System.out.println(uid + " " + uname+" "+usex+""+uphone+""+uaddress+""+uemail);

con.close();

很显然是驱动的问题,必须加载。具体可HI我追问

额..我是初学者不是很懂..他说不是真实头像Hi不了你啊哈哈..- -

参考技术A mysql 的jdbc驱动 jar包,你没有放到 lib文件夹下面吧 ?
必须得放....追问

啥..那是啥..T.T...lib文件夹是啥..在哪..
对不起我是初学者..要做啥课程设计我好纠结-_-

java连接sql server 2005的问题 java.sql.SQLException: No suitable driver

java.sql.SQLException: No suitable driver



找了N久未解决,在群里经过几个牛人们指点终于搞点,现总结如下



1 驱动包用的不对



2 连接串的写法不同于2000







//JDBC for SQL server 2000写法:

String DBDRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

//JDBC for SQL server 2005写法:


String DBDRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";








2003 写法

access.url=jdbc:microsoft:sqlserver://192.168.1.136:1433;DatabaseName=GameDB

2005 写法

String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=dbName";






附用的配置文件(2005)



-------------



drivers=com.microsoft.sqlserver.jdbc.SQLServerDriver

logfile=./logs/dblog.txt

access.maxconn=50

access.url=jdbc:sqlserver://192.168.1.136:1433;DatabaseName=Game23DB

access.user=sa

access.password=hujie


-------附属性文件建立及dbcontect-----


用配置文件连接数据库
1. Eclipse中,在src目录下建立db.properties文件,在里面配置数据库连接所需的 Driver,url,user,possword ,注意等号左右不能空格

如:
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://localhost:1433;databaseName=restrant
user=sa
password=110 2.写一个数据库连接类
import java.io.IOException;
import java.sql.*;
import java.util.Properties; public Connection getCon()
Connection con = null;
Properties properties = new Properties();
try
properties.load(this.getClass().getResourceAsStream(
"/db.properties"));
String driver = properties.getProperty("driver");
String url = properties.getProperty("url");
String user = properties.getProperty("user");
String password = properties.getProperty("password"); try
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
catch (ClassNotFoundException e)
// TODO Auto-generated catch block
e.printStackTrace();
catch (SQLException e)
// TODO Auto-generated catch block
e.printStackTrace();

catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();

return con;


sql 2000 需要引用三个jar包 msbase.jar,mssqlserver.jar,msutil.jar



sql 2005 需要引用一个jar包 sqljdbc.jar

以上是关于JAVA报错no suitable driver的主要内容,如果未能解决你的问题,请参考以下文章

java连接mysql, No suitable driver

RestTemplate HttpMessageConverter报错的解决方案no suitable HttpMessageConverter

数据库连接常见报错及解决java.sql.SQLException No suitable driver

数据库连接常见报错及解决java.sql.SQLException No suitable driver

(转) java 通过 jdbc 链接 ms sql server 中出现 "no suitable driver for ..."

项目启动报错:No suitable driver found for jdbc:oracle:thin:@192.168.7.146:1521:oracle