我是这方面的新编程,我遇到了一些驱动程序的问题,有点:
I'm new at this area programming and I got some problems with driver, kinda:
MySql在我直接与客户端一起使用时工作正常,问题是我无法使用MySql建立连接tomcat
MySql is working fine when I'm using it directly with client, problem is I can't make a connection tomcat with MySql
我将所有驱动程序放在WEB-INF / lib
I put all my drivers at WEB-INF/lib
使用mysql 5.7,tomcat 9.1,java 8,IntellijIdea 2016.1.1
using mysql 5.7, tomcat 9.1, java 8, IntellijIdea 2016.1.1
>
>
> java.sql.SQLException:没有为jdbc找到合适的驱动程序:mysql / localhost:3306 / world 在java.sql.DriverManager.getConnection(DriverManager.java:689) 在java.sql.DriverManager.getConnection(DriverManager.java:247) 在Db.main(Db.java:20)
》 java.sql.SQLException: No suitable driver found for jdbc:mysql/localhost:3306/world at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:247) at Db.main(Db.java:20)
所以这是我的代码:
so here is my code:
import java.io.Serializable;
import java.sql.*;
public class Db implements Serializable{
public static void main(String args[]){
Connection connection;
final String dbURL = "jdbc:mysql/localhost:3306/world";
final String username = "root";
final String pswd = "******";
try{
DriverManager.getDrivers();
connection = DriverManager.getConnection(dbURL,username,pswd);
Statement statement = connection.createStatement();
String query = "SELECT * FROM city WHERE Name LIKE 'New%'";
ResultSet result = statement.executeQuery(query);
while(result.next()){
int id = result.getInt("ID");
String name = result.getString("Name");
String cCode = result.getString("CountryCode");
String district = result.getString("District");
int pop = result.getInt("Population");
System.out.print("id = "+id+"《/br》Name = "+name+
"《/br》Code = "+cCode+"《/br》District = "+district+
"《/br》Population = "+pop+"《/br》");
}
}catch (SQLException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
}