Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.Random;
- import java.util.Scanner;
- public class DatabaseInsert {
- Random rand = new Random();
- public DatabaseInsert() throws SQLException{
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Connection connection = null;
- try {
- connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cinemator", "postgres", "admin");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return;
- }
- Statement stmt = connection.createStatement();
- int i = 1, c;
- int id;
- String meno;
- String heslo;
- String rarity;
- Scanner sc = new Scanner(System.in);
- while (i < 30) {
- System.out.print("meno ");
- meno = sc.next();
- System.out.print("priezvisok ");
- String priezvisko = sc.next();
- System.out.print("rola ");
- int rola = sc.nextInt();
- String opis = "fasa";
- System.out.print("pohlavie ");
- String pohlavie = sc.next();
- String sql = String.format("INSERT INTO artist VALUES ('%d','%s','%s','%s', '%s', '%d');", i, meno, priezvisko, opis, pohlavie, rola);
- stmt.executeUpdate(sql);
- i++;
- }
- }
- public static void main(String[] args) throws SQLException {
- new DatabaseInsert();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement