Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package login;
- import javax.inject.Named;
- import javax.enterprise.context.SessionScoped;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.Time;
- import java.time.LocalTime;
- import java.util.ArrayList;
- @Named(value = "post")
- @SessionScoped
- public class Post implements Serializable {
- String text;
- String imge = "";
- String sound = "";
- String video = "";
- String Name = "";
- public String getName() {
- Variable v = new Variable();
- return v.Name;
- }
- public void setName(String Name) {
- Variable v = new Variable();
- this.Name = v.Name;
- }
- public String getText() {
- return text;
- }
- public void setText(String text) {
- this.text = text;
- }
- public void addposts(String User) {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
- Statement STF = MC.createStatement();
- String R = "Insert into post(User,Text,time) VALUES ('" + User + "','" + text + "','" + Time.valueOf(LocalTime.now()) + "')";
- STF.executeUpdate(R);
- text = "";
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
- System.out.println(E);
- }
- }
- ArrayList<poster> Cas = new ArrayList<>();
- public static ArrayList<poster> Cluster = new ArrayList<>();
- public static int pageIndexs = 0;
- int pageIndex = 1;
- int pages = 1;
- public void prev() {
- if (pageIndexs > 1) {
- pageIndexs--;
- pageIndex = pageIndexs;
- int i = 1;
- Cas.clear();
- for (poster r : Cluster) {
- if (i >= pageIndexs * 8 && i < (pageIndexs * 8) + 8) {
- Cas.add(r);
- }
- i++;
- }
- }
- }
- public void next() {
- if (pageIndexs < pages) {
- pageIndexs++;
- pageIndex = pageIndexs;
- int i = 1;
- Cas.clear();
- for (poster r : Cluster) {
- if (i >= pageIndexs * 8 && i < (pageIndexs * 8) + 8) {
- Cas.add(r);
- }
- i++;
- }
- }
- }
- public void getallposts(String User) {
- Cas.clear();
- Cluster.clear();
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
- Statement STF = MC.createStatement();
- ResultSet R = STF.executeQuery("Select * from post where User='" + User + "'");
- while (R.next()) {
- poster p = new poster();
- p.postes = R.getString("Text");
- p.Times = R.getTime("time");
- p.Sounds = R.getString("Sound");
- p.Videos = R.getString("video");
- p.Imges = R.getString("Imge");
- if (Cas.size() < 8) {
- Cas.add(p);
- }
- Cluster.add(p);
- }
- if (Cluster.size() % 8 > 0) {
- int g = Cluster.size() % 8;
- pages = (Cluster.size() - g) / 8;
- pages++;
- } else {
- pages = Cluster.size() / 8;
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
- System.out.println(E);
- }
- }
- public Post() {
- }
- public int getPageIndex() {
- return pageIndex;
- }
- public void setPageIndex(int pageIndex) {
- this.pageIndex = pageIndex;
- }
- public int getPages() {
- return pages;
- }
- public void setPages(int pages) {
- this.pages = pages;
- }
- public ArrayList<poster> getCas() {
- return Cas;
- }
- public void setCas(ArrayList<poster> Cas) {
- this.Cas = Cas;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement