import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class InsertData { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/mydatabase"; String username = "root"; String password = "password"; try { Connection connection = DriverManager.getConnection(url, username, password); Statement statement = connection.createStatement(); String insertQuery = "INSERT INTO mytable (column1, column2) VALUES ('value1', 'value2')"; int rowsAffected = statement.executeUpdate(insertQuery); System.out.println("Rows affected: " + rowsAffected); statement.close(); connection.close(); } catch (SQLException e) { System.out.println("插入失败原因: " + e.getMessage()); } } }
上面是“在Java项目中如何更新MySQL数据库”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_14923.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!