-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoe.java
76 lines (61 loc) · 1.91 KB
/
shoe.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
72
73
74
75
76
package web;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class shoe extends ActionSupport{
/**
*
*/
/*system.out("helloworld")*/
private static final long serialVersionUID = 1L;
private static Connection connection = null;
private static Statement statement ;
private static ResultSet resultSet;
private String Title;
private List<Authorbean> list = new ArrayList<Authorbean>();
public String getTitle() {
return Title;
}
public void setTitle(String Title) {
this.Title = Title;
}
public String execute() throws Exception{
String sql = String.format("select author.AuthorID,Name,Age,Country from Author,book where book.Title = '%s'",Title);
Class.forName("com.mysql.jdbc.Driver");
// connection = DriverManager.getConnection("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_hithu","mlxxm110jl","ijk4h4l0j4xzzjyw51w43j3kwlmi1zjx1kiiy5l2");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/bookdb","root","danshen94ss");
statement = connection.createStatement();
resultSet = statement.executeQuery(sql);
while(resultSet.next())
{
Authorbean author = new Authorbean();
author.setAuthorID(resultSet.getString(1));
author.setName(resultSet.getString(2));
author.setAge(resultSet.getString(3));
author.setCountry(resultSet.getString(4));
list.add(author);
}
this.closeConnection();
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", list);
return SUCCESS;
}
public void closeConnection()
{
try{
if(connection !=null){
connection.close();
connection = null;
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}