Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
package com.slimfast.action;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.ActionSupport;
import com.slimfast.Modal.movie_pojo;
import com.slimfast.manager.manager;
public class Delete extends ActionSupport {
private static final long serialVersionUID = 1L;
private Boolean Success;
private manager mag;
private movie_pojo movie;
private String[] ids;
public String[] getIds() {
return ids;
}
public void setIds(String[] ids) {
this.ids = ids;
}
public Boolean getSuccess() {
return Success;
}
public void setSuccess(Boolean success) {
Success = success;
}
public manager getMag() {
return mag;
}
public void setMag(manager mag) {
this.mag = mag;
}
public movie_pojo getMovie() {
return movie;
}
public void setMovie(movie_pojo movie) {
this.movie = movie;
}
public String execute()
{
try {
@SuppressWarnings("resource")
ApplicationContext context= new ClassPathXmlApplicationContext("applicationcontext.xml");
mag=(manager) context.getBean("ManagerImpl");
Boolean delete= mag.DeleteMovie(ids);
if(delete==true) {
setSuccess(true);
}
else {
setSuccess(false);
}
}
catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
}
moviedb_implementation
package com.slimfast.DAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.slimfast.movie;
import com.slimfast.Modal.movie_pojo;
public class movieDB_implementation implements moviedb {
ArrayList<movie_pojo> custList= new ArrayList<movie_pojo>();
public ArrayList<movie_pojo> getAllMovies(int start, int limit, String title, String director, String language,int release_year)
{
Connection con=null;
try {
@SuppressWarnings("unused")
Statement stmt=null;
@SuppressWarnings("unused")
String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
Class.forName(JDBC_DRIVER);
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String mysqlUrl="jdbc:mysql://localhost:3306/sakila";
con = DriverManager.getConnection(mysqlUrl,"root","root");
stmt=con.createStatement();
if(title!=null && director!=null && language!=null) {
ResultSet rs = con.createStatement().executeQuery("select * from film where title='" + title + "' && director='" + director + "'&& release_year='" + release_year + "'&& language_id='" + language + "' && isDeleted=0 ");
System.out.print(rs);
while(rs.next()) {
movie_pojo custObj= new movie_pojo();
custObj.setTitle(rs.getString("title"));
custObj.setDescription(rs.getString("description"));
custObj.setRelease(Integer.parseInt(rs.getString("release_year").substring(0,4)));
custObj.setLanguage(rs.getString("language_id"));
custObj.setDirector(rs.getString("director"));
custObj.setRating(rs.getString("rating"));
custObj.setFeatures(rs.getString("special_features"));
custObj.setfilm_id(rs.getInt("film_id"));
custList.add(custObj);
}
}
else {
ResultSet rs = con.createStatement().executeQuery("SELECT * from film where isDeleted=0 limit "+start + ","+limit+";");
System.out.print(rs);
while(rs.next()) {
movie_pojo custObj1= new movie_pojo();
custObj1.setTitle(rs.getString("title"));
custObj1.setDescription(rs.getString("description"));
custObj1.setRelease(rs.getInt("release_year"));
custObj1.setLanguage(rs.getString("language_id"));
custObj1.setDirector(rs.getString("director"));
custObj1.setRating(rs.getString("rating"));
custObj1.setFeatures(rs.getString("special_features"));
custObj1.setfilm_id(rs.getInt("film_id"));
custList.add(custObj1);
}
}
}catch(Exception e)
{
e.printStackTrace();
System.out.println("Ërror in DAO Impl");
}
finally {
try
{
if(con!=null)
con.close();
}
catch(SQLException se)
{
se.printStackTrace();
}
}
return custList;
}
public Boolean addMovies(String title,int release,String features,String rating,String language,String director,String description) {
try {
// Initialize the database
//String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/sakila";
String USER = "root";
String PASS = "root";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(DB_URL,USER,PASS);
// Create a SQL query to insert data into demo table
// demo table consists of two columns, so two '?' is used
String sql = "INSERT INTO film (title, release_year,special_features,rating,language_id,director,description) VALUES (?,?,?,?,?,?,?)";
PreparedStatement statement = con.prepareStatement(sql);
statement.setString(1,title);
statement.setInt(2,release);
statement.setString(3,features);
statement.setString(4,rating);
statement.setString(5,language);
statement.setString(6,director);
statement.setString(7,description);
statement.executeUpdate();
// Close all the connections
statement.close();
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
public Boolean EditMovies(int film_id,String title,int release_year,String special_features,String rating,int language,String director,String description) {
String DRIVER="com.mysql.cj.jdbc.Driver";
String URL="jdbc:mysql://localhost:3306/sakila";
String UN="root";
String PW="root";
try {
Class.forName(DRIVER);
try {
Connection cn=DriverManager.getConnection(URL,UN,PW);
PreparedStatement pst=cn.prepareStatement("UPDATE film SET title=?,release_year=?,special_features=?,rating=?,language_id=?,director=?,description=? WHERE film_id=?");
pst.setString(1, title);
pst.setInt(2, release_year);
pst.setString(3, special_features);
pst.setString(4, rating);
pst.setInt(5, language);
pst.setString(6, director);
pst.setString(7, description);
pst.setInt(8, film_id);
pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
public Boolean DeleteMovie(String []ids) {
try {
// Initialize the database
//String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/sakila";
String USER = "root";
String PASS = "root";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(DB_URL,USER,PASS);
// Create a SQL query to insert data into demo table
// demo table consists of two columns, so two '?' is used
String delete="UPDATE film set isDeleted=1 where film_id=?;";
for(int i=0;i<ids.length;i++)
{
PreparedStatement ps=con.prepareStatement(delete);
ps.setLong(1,Long.parseLong(ids[i]));
ps.executeUpdate();
}
// Close all the connections
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
moviedb
package com.slimfast.DAO;
import java.util.ArrayList;
import com.slimfast.Modal.movie_pojo;
public interface moviedb {
ArrayList<movie_pojo> getAllMovies(int start, int limit, String title, String director, String language,int release_year);
Boolean addMovies(String title,int release,String features,String rating,String language,String director,String description);
Boolean EditMovies(int film_id,String title,int release_year,String special_features,String rating,int language,String director,String description);
Boolean DeleteMovie(String []ids);
}
manager
package com.slimfast.manager;
import java.util.ArrayList;
import com.slimfast.DAO.moviedb;
import com.slimfast.Modal.movie_pojo;
;
public class manager implements movie_manager {
private moviedb obj;
@Override
public ArrayList<movie_pojo> getAllMovies(int start, int limit, String title, String director, String language, int release_year) {
// TODO Auto-generated method stub
return obj.getAllMovies(start, limit, title, director, language, release_year);
}
public moviedb getObj() {
return obj;
}
public void setObj(moviedb obj) {
this.obj = obj;
}
@Override
public Boolean addMovies(String title, int release, String features, String rating, String language,
String director, String description) {
// TODO Auto-generated method stub
return obj.addMovies(title, release, features, rating, language, director, description);
}
@Override
public Boolean EditMovies(int film_id, String title, int release_year, String special_features, String rating,
int language, String director, String description) {
// TODO Auto-generated method stub
return obj.EditMovies(film_id, title, release_year, special_features, rating, language, director, description);
}
@Override
public Boolean DeleteMovie(String[] ids) {
// TODO Auto-generated method stub
return obj.DeleteMovie(ids);
}
}
movie_manager
package com.slimfast.manager;
import java.util.ArrayList;
import com.slimfast.Modal.movie_pojo;
public interface movie_manager {
ArrayList<movie_pojo> getAllMovies(int start, int limit, String title, String director, String language,int release_year);
Boolean addMovies(String title,int release,String features,String rating,String language,String director,String description);
Boolean EditMovies(int film_id,String title,int release_year,String special_features,String rating,int language,String director,String description);
Boolean DeleteMovie(String []ids);
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team