Help! Made a MySQL database running phpMyAdmin. And he created a table there. I use library MySQL_Connector. In order to get data from it, I use this code:

try{ Connection connection; String driverName = "com.mysql.jdbc.Driver"; Class.forName(driverName); String baseName = "ej3"; String serverName = "localhost"; String _url = "jdbc:mysql://"+serverName+"/"+baseName; String userName = "root"; String password = ""; connection = DriverManager.getConnection(_url, userName, password); String ask = "SELECT * FROM pupils"; Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(ask); String tempN,tempSN; while(rs.next()) { tempN = rs.getString("fName"); tempSN = rs.getString("sName"); addPupil(new Pupil(tempN, tempSN)); } connection.close(); }catch(Exception e){} 

He works. And how to do so, not to get the value, and write?

  • What exactly you can not connect? - JVic
  • 2
    Well, it is ... instead of SELECT write INSERT ... - Morlok
  • Your question name is incorrectly formulated, you do not need help with connecting and you do not need it with Java. You need to learn SQL. And in short, yes ... You need INSERT sql-tutorial.ru/en/book/operator_insert.html - Mikhail Rebrov
  • one
    Instead of executeQuery, you can see executeUpdate. - Dan Irkutskiy
  • I tried the place SELECT * FROM pupils to write INSERT INTO pupils (fName, sName) VALUES ('Vasa', 'Peta') but does not help. - KotFind

0