SHARE
TWEET

Untitled

a guest Mar 20th, 2017 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package films;
  2. import java.sql.*;
  3.  
  4. import java.util.logging.*;
  5. import java.util.Random;
  6.  
  7. public class Films {
  8.  
  9. public static Connection Soedinenie = null;
  10.  
  11. public static Statement stmt = null;
  12.  
  13. public static ResultSet Rezultat = null;
  14.  
  15.  
  16.  
  17. public static Random Random = new Random();
  18.  
  19. public static void main(String[] args){//ГЛАВНЫЙ МЕТОД;
  20. try{
  21. String url = "jdbc:postgresql://localhost:5432/films";
  22. String name = "postgres";
  23. String password = "privet";//пароль
  24. Class.forName("org.postgresql.Driver");//загружаем драйвер
  25.  
  26.  
  27.  
  28. Soedinenie = DriverManager.getConnection(url, name, password);//создаем соединение
  29. stmt = Soedinenie.createStatement();
  30. }
  31. catch(ClassNotFoundException | SQLException ex){
  32. System.out.println("errors");}finally{
  33. ///////////////////////////////////////////////////////////////////////////////////////////////////
  34.  
  35. // IskomoeSlovo("А");
  36. IskomoeSlovo("'; delete from films---"); // KAAAAAAAAAAAAAAAAAAAAAAAKKKKKKKKKKKK??? D:
  37.  
  38. public static void IskomoeSlovo(String Slovo){//ИЩЕМ ЭТО СЛОВО В НАЗВАНИЮ;
  39. try{
  40.  
  41. /*Как быть?*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42.  
  43.  
  44. Rezultat = stmt.executeQuery("SELECT * FROM films" + " WHERE name like '%"+Slovo+"%';");
  45. /while(Rezultat.next()){
  46. System.out.println(Rezultat.getRow()+"\t"+Rezultat.getString("name")+"\t"+"\n"+Rezultat.getString("genre")+"\t"+"\n"+Rezultat.getInt("raiting"));}
  47. }
  48. catch(Exception ex){ Logger.getLogger(Films.class.getName()).log(Level.SEVERE, null, ex);}
  49. End();}
  50.  
  51.  
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top