Could you help me organize reading from a database. I'm under Windows. I get this error message: java.sql.SQLException: No suitable driver found for localhost
This is an extract from my code:
public class JavaApplication10 {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
Properties connInfo = new Properties();
connInfo.put("characterEncoding","UTF8");
connInfo.put("user", "root");
connInfo.put("password", "goskomstat");
conn = DriverManager.getConnection("localhost", connInfo);
Being in Windows command line I can type: C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin>mysql -u root -p
Then I ehter the password 'goskomstat' and can operate my databases.
Could you give me a hint what to do?
You need to define your connection as follows:
conn = DriverManager.getConnection("jdbc:mysql://localhost/", connInfo);
That allows you to specify the JDBC driver by using the specific URI prefix.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.