get メソッドと set メソッドの両方を使用して Java でプログラムを作成しました....しかし、目的の出力が得られません。表示された表の
package com.glomindz.mercuri.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.glomindz.mercuri.pojo.User;
import com.glomindz.mercuri.util.MySingleTon;
public class UserServicesDAO {
private Connection connection;
public UserServicesDAO() {
// connection = new MySingleTon().getConnection();
connection = MySingleTon.getInstance().getConnection();
}
public List<User> get_all_data() {
List<User> usersList = new ArrayList<User>();
String query = "SELECT * FROM spl_user_master";
try {
PreparedStatement stmt = connection.prepareStatement(query);
boolean execute = stmt.execute();
System.out.println(execute);
ResultSet resultSet = stmt.getResultSet();
System.out.println(resultSet.getMetaData());
while (resultSet.next()) {
User user = new User();
user.setId(resultSet.getInt("id"));
user.setName(resultSet.getString("name"));
user.setEmail(resultSet.getString("email"));
user.setMobile(resultSet.getString("mobile"));
user.setPassword(resultSet.getString("password"));
user.setRole(resultSet.getString("role"));
user.setStatus(resultSet.getString("status"));
user.setLast_udpate(resultSet.getString("last_update"));
usersList.add(user);
}
}
}
public List<User> set_all_data() {
List<User> usersList = new ArrayList<User>();
try {
PreparedStatement stmt = connection.prepareStatement("INSERT INTO spl_user_master(name,email,mobile,password,role,status,last_update)VALUES(?,?,?,?,?,?,?)");
stmt.setString(1, "Charlie Sheen");
stmt.setString(2, "help@glomindz.com");
stmt.setString(3, "9554087107");
stmt.setString(4, "cbf91a71c21d5ec348b0c749b2f0055k");
stmt.setString(5, "user");
stmt.setString(6, "3");
stmt.setString(7, "2013-07-02 22:05:16");
boolean execute = stmt.execute();
System.out.println(execute);
stmt.getResultSet();
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return usersList;
}
public static void main(String[] args) {
UserServicesDAO userdao = new UserServicesDAO();
List<User> data = userdao.get_all_data();
List<User> data1 = userdao.set_all_data();
System.out.println(data);
System.out.println(data1);
System.exit(0);
}
}
コードの何が問題なのか教えてください