我正在Java 1.7中编写一些应用程序。我想知道如果我做顺序的sql语句,我将来会遇到什么样的问题。有没有可能在prepareStatement和resultSet中遇到一些问题?
我的代码看起来像这样:
public multipleArrays selectQuery(id){
//INITIALIZATION CODE, MAKE CONNECTION, INITIALIZE QUERY
preperedStatement= (PreparedStatement) connection.prepareStatement("SELECT * FROM USER WHERE id_user = ? ");
preperedStatement.setInt(1, id);
resultSet = preperedStatement.executeQuery();
//CREATE ARRAYLIST OF PRIVATE OBJECT USER //
id = resultSet.getInt("role_id");
preperedStatement= (PreparedStatement) connection.prepareStatement("SELECT * FROM ROLE WHERE id_role= ? ");
preperedStatement.setInt(1, id);
resultSet = preperedStatement.executeQuery();
//CREATE ARRAYLIST OF PRIVATE OBJECT ROLE //
id=resultSet.getInt("data_id");
preperedStatement= (PreparedStatement) connection.prepareStatement("SELECT * FROM DATA WHERE id_data = ? ");
preperedStatement.setInt(1, id);
resultSet = preperedStatement.executeQuery();
//CREATE ARRAYLIST OF PRIVATE OBJECT DATA //
id=resultSet.getInt("issue_id");
preperedStatement= (PreparedStatement) connection.prepareStatement("SELECT * FROM ISSUE WHERE issue_id = ? ");
preperedStatement.setInt(1, id);
resultSet = preperedStatement.executeQuery();
//CREATE ARRAYLIST OF PRIVATE OBJECT ISSUE//
//CLOSE CONNECTION AND RETURN MULTIPLE ARRAYS
}
答案 0 :(得分:2)
您将来可能遇到的主要问题是:
select * from ISSUE i, DATA d, ROLE r, USER u WHERE u.id_user = ?
AND r.id_role = u.role_id AND data.id_data = r.data_id
AND i.issue_id = d.issue_id;
答案 1 :(得分:1)
如果它现在正在工作,它应该继续工作,只要你明白你想要做什么。继续您的程序,直到遇到错误。从那里你可以调试你的编码,并解决问题。您的代码似乎足够干净,因此您可以轻松识别您碰巧遇到的任何错误。稍后测试您的代码,如果您以后遇到错误请求特定问题的帮助。