Good afternoon, I run ready .jar on Linux but an error pops up
java.sql.SQLException: No suitable driver found for jdbc: mysql
I use mysql-connector-java-5.1.39-bin to connect to SQL. It is not clear that it is connected in the project and it lies in the jar and runs on windows.
/******************ПОДКЛЮЧАЕМСЯ К БАЗЕ ДАННЫХ*********************/ //JDBC URL, username and password of MySQL server private static final String url = "jdbc:mysql:"; private static final String user = ""; private static final String password = ""; /**************************КОНЕЦ***************************/ // --------ДОБАВЛЕНИЕ ДАННЫХ-------- try{ String query = " INSERT INTO coordinates_centre (id, la, lo\n"// добавляем данные в таблицу +", ti, sp)\n" + "VALUES('"+id+"', '"+la+"', '"+lo+"', '"+ti+"', '"+sp+"');"; // opening database connection to MySQL server con = DriverManager.getConnection(url, user, password); // getting Statement object to execute query stmt = con.createStatement(); // executing SELECT query rs = stmt.executeUpdate(query); } catch (SQLException sqlEx) { sqlEx.printStackTrace(); } finally { //close connection ,stmt and resultset here try { con.close(); } catch(SQLException se) { /*can't do anything */ } try { stmt.close(); } catch(SQLException se) { /*can't do anything */ } } // --------КОНЕЦ--------
classpath. The java command line can somehow be set using the environment variable. Or the driver jar is also listed among the parameters in the command line. And you can leave the general library in a special folder, I do not remember the name. - Sergey