खोज…
परिचय
एक ResultSet ऑब्जेक्ट एक कर्सर रखता है जो डेटा की वर्तमान पंक्ति की ओर इशारा करता है। प्रारंभ में कर्सर पहली पंक्ति से पहले स्थित होता है। अगली विधि कर्सर को अगली पंक्ति में ले जाती है, और क्योंकि यह गलत हो जाता है जब ResultSet ऑब्जेक्ट में अधिक पंक्तियाँ नहीं होती हैं, तो इसका उपयोग परिणाम लूप के माध्यम से पुनरावृति करने के लिए कुछ समय लूप में किया जा सकता है
परिणाम सेट
ResultSet
बनाने के लिए आपको एक Statement
या PrepapredStatement
बनाना चाहिए:
स्टेटमेंट के साथ रिजल्टसेट बनाएं
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(
"jdbc:somedb://localhost/databasename", "username", "password");
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT * FROM my_table");
} catch (ClassNotFoundException | SQLException e) {
}
PrepapredStatement के साथ रिजल्टसेट बनाएं
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(
"jdbc:somedb://localhost/databasename", "username", "password");
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM my_table");
ResultSet result = preparedStatement.executeQuery();
} catch (ClassNotFoundException | SQLException e) {
}
जांचें कि आपके रिजल्टसेट की जानकारी है या नहीं
if (result.next()) {
//yes result not empty
}
ResultSet से जानकारी प्राप्त करें
कई प्रकार की जानकारी आप अपने ResultSet
से प्राप्त कर सकते हैं जैसे String, int, boolean, float, Blob
, ... जानकारी प्राप्त करने के लिए आपको एक लूप या एक सरल का उपयोग करना था यदि:
if (result.next()) {
//get int from your result set
result.getInt("id");
//get string from your result set
result.getString("username");
//get boolean from your result set
result.getBoolean("validation");
//get double from your result set
result.getDouble("price");
}
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow