-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqliteHandler.java
43 lines (36 loc) · 1.19 KB
/
SqliteHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SqliteHandler{
public static ResultSet getAllMoviResult(Statement statement, String table_name) {
try {
return statement.executeQuery("select * from " + table_name);
} catch (SQLException e) {
System.err.println(e.getMessage());
}
return null;
}
public static void InsertNewMovie(Statement statement, String table_name, Movie movie) {
String insert = "INSERT INTO " + table_name + " values ('" + movie.getMovieName() + "','" + movie.getActorName()
+ "','" + movie.getDirectorName() + "'," + movie.getYearOfRelease() + ")";
try {
statement.executeUpdate(insert);
} catch (SQLException e) {
System.err.println(e.getMessage());
}
}
public static Movie FatchMovieFromDataBase(ResultSet result){
Movie movie;
try {
String MovieName = result.getString("name");
String ActorName = result.getString("actor");
String DirectorName = result.getString("director");
int year = result.getInt("year");
movie = new Movie(MovieName,ActorName,DirectorName,year);
return movie;
} catch (SQLException e) {
System.err.println(e.getMessage());
}
return null;
}
}