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
|
public class Open
{
public List<Group> groupList = new ArrayList<Group>();
public void LoadGroup()
{
try {
try
{
String userName = "***";
String password = "***";
String url = "jdbc:mysql://localhost/MyDiaryDataBase";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url, userName, password);
Statement state = conn.createStatement();
ResultSet result = state.executeQuery("SELECT * FROM `group`");
while(result.next())
{
groupList.add(new Group (result.getObject(2).toString(),result.getObject(3).toString()));
}
result.close();
state.close();
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
}
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager