Created
May 10, 2015 07:42
-
-
Save tongtie/c4465bca64ec034d7a98 to your computer and use it in GitHub Desktop.
service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package service; | |
import javax.jws.WebService; | |
import java.sql.*; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import com.bean.PersonBean; | |
/** | |
* Created by mrt on 2015/5/10. | |
*/ | |
@WebService(endpointInterface = "service.Persons") | |
public class PersonList implements Persons { | |
public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | |
public static final ArrayList<PersonBean> list = new ArrayList<PersonBean>(); | |
public ArrayList<PersonBean> getPersonList() { | |
String dbUrl = "jdbc:mysql://localhost:3306/databaseWeb"; | |
String dbClass = "com.mysql.jdbc.Driver"; | |
String userName = "root", password = "123024"; | |
try { | |
Class.forName(dbClass); | |
Connection con = DriverManager.getConnection (dbUrl, userName, password); | |
Statement stmt = con.createStatement(); | |
String query = "select * from tb_person"; | |
ResultSet rs = stmt.executeQuery(query); | |
while (rs.next()) { | |
PersonBean bean = new PersonBean(); | |
bean.setId(String.valueOf(rs.getInt("id"))); | |
bean.setName(rs.getString("name")); | |
bean.setSex(rs.getString("sex")); | |
bean.setBirthday(dateFormat.format(rs.getDate("birthday"))); | |
list.add(bean); | |
} | |
con.close(); | |
} //end try | |
catch(ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
catch(SQLException e) { | |
e.printStackTrace(); | |
} | |
finally { | |
return list; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment