-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlOop.java
71 lines (60 loc) · 1.97 KB
/
SqlOop.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package controllers;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MetaGet {
private String meta_description;
private String origin;
private String meta_title;
private Statement statement = null;
private ResultSet rs = null;
public MetaGet (String origin, Connection connection) {
this.meta_title = this.getTitle(origin, connection);
this.meta_description = this.getDescription(origin, connection);
}
//retrieve title from database to store in database
public String getTitle(String origin, Connection connection) {
String title = "";
try {
PreparedStatement statement = null;
statement = connection.prepareStatement( "SELECT title FROM pages WHERE slug=? LIMIT 1;");
statement.setString(1, origin);
rs = statement.executeQuery();
if(rs.next()) {
title = rs.getString("title");
}
}
catch(SQLException se) {
se.printStackTrace();
}
return title;
}
//get description from database to store in database
public String getDescription(String origin, Connection connection) {
String description = "";
try {
PreparedStatement statement = null;
statement = connection.prepareStatement("SELECT meta_description FROM pages WHERE slug=? LIMIT 1;");
statement.setString(1, origin);
System.out.println("Check statement query : "+statement.toString());
rs = statement.executeQuery();
if(rs.next()) {
description = rs.getString("meta_description");
}
}
catch(SQLException se) {
se.printStackTrace();
}
return description;
}
//show title after create new object
public String showTitle() {
return this.meta_title;
}
//show description after creating new object
public String showDescription() {
return this.meta_description;
}
}