Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.programm.freeman;
- import org.programm.Magazine;
- import java.sql.*;
- import java.util.List;
- /**
- * Created by freeman on 13.10.2015.
- */
- public class DB {
- private Long id;
- private String group;
- private Integer countStudent;
- private String classroomTeacher;
- private String edit;
- private Boolean allSigned;
- // JDBC URL, username and password of MySQL server
- private static final String url = "jdbc:mysql://localhost:3306/atcpcondb";
- private static final String user = "root";
- private static final String password = "root";
- // JDBC variables for opening and managing connection
- private static Connection con;
- private static Statement stmt;
- private static ResultSet rs;
- public void connectBD()
- {
- try {
- // opening database connection to MySQL server
- con = DriverManager.getConnection(url, user, password);
- // getting Statement object to execute query
- stmt = con.createStatement();
- } 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 */ }
- try {
- rs.close();
- } catch (SQLException se) { /*can't do anything */ }
- }
- }
- public void addAll(List<Magazine> list){
- for(int i=0; i<list.size();i++){
- id = list.get(i).getId();
- group = list.get(i).getGroup();
- countStudent = list.get(i).getCountStudent();
- classroomTeacher = list.get(i).getClassroomTeacher();
- edit = list.get(i).getEdit();
- allSigned = list.get(i).getAllSigned();
- String query = "INSERT INTO atcpcondb.magazine (id, group, countStudents, classroomTeacher, edit, allSigned) \n" +
- " VALUES ("+id+","+group+","+countStudent+", "+classroomTeacher+","+edit+","+allSigned+");";
- // executing SELECT query
- try {
- stmt.executeUpdate(query);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement