Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class DBTest {
- private static final String USERNAME = "root";
- private static final String PASSWORD = "root";
- private static final String DATABASEURL = "jdbc:mysql://localhost:3306/test";
- public static void main(String[] args) {
- try {
- //создаем соеднинение для базы данных
- Class.forName("com.mysql.jdbc.Driver");
- Connection connection = DriverManager.getConnection(DATABASEURL, USERNAME, PASSWORD);
- Statement statement = connection.createStatement();
- String thisName = "ASFDF", thisGenre="ASDASDAS";
- double thisPrice = 23;
- statement.executeUpdate("INSERT INTO GameShop(name,genre,price) VALUE " +
- "('"+thisName+"','"+thisGenre+"','"+thisPrice+"')");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static synchronized void addGames(StandartGame ... gamez) {
- try {
- //создаем соеднинение для базы данных
- Class.forName("com.mysql.jdbc.Driver");
- Connection connection = DriverManager.getConnection(DATABASEURL, USERNAME, PASSWORD);
- Statement statement = connection.createStatement();
- String thisName, thisGenre;
- double thisPrice;
- for (StandartGame stg : gamez) {
- thisName = stg.getName();
- thisGenre = stg.getGenre();
- thisPrice = stg.getPrice();
- statement.executeUpdate("insert into GameShop (name, genre, price) VALUE " +
- "('"+thisName+"', '"+thisGenre+"', '"+thisPrice+"')");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment