I want to print it out through a normal array, not an array list.
I just don't know how.
Please give me a hint.ㅜ<
package inosys.db;
import java.lang.reflect.Array;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class DbConnection {// class name declaration, first letter uppercase letter of class name
public static void main(String[] args) {
// Declare outside the try area because it should be used in the final area
Connection conn = null; // DB connection processing
Run Statement stmt = null; // sql
ResultSetters = null; // Exploring records
String url = "jdbc:oracle:thin:@localhost:1522:orcl";
String userid = "test3";
String userpw = "1234";
String sql = "SELECT * FROM member "; //
int row = rs.getRow();
String[] strArray = new String[row];
if(rs.next()) {
for(int i=0; rs.next(); i++){
strArray[i] = rs.getString("");
}
}
try {
Class.forName ("oracle.jdbc.driver.OracleDriver"); // driver connection
// getConnection (connection string, ID, password)
conn = DriverManager.getConnection(url, userid, userpw);
stmt = conn.createStatement();// sql execution object
// The result of executing select query is passed to the result set
rs = stmt.executeQuery(sql);
// executeQuery on select
// When not select - executeUpdate();
while (rs.next()) {
JobBean = new JobBean(); // create jobBean object
bean.setId(rs.getString("ID"); get Id data as //rs.get
bean.Get name data as setName(rs.getString("name"); //rs.get
bin.setPasswd(rs.getString("passwd")); import passwd data into //rs.get
bin.setAddress(rs.getString("address")); get address data as //rs.get
}
String[] arr = new String[jobList.size()];
int size=0;
for (inti = 0; i < arr.length; i++) { output in repeat statement
System.out.println ("ID:" + get(i).getId());
System.out.println ("Name:" + get(i).getName());
System.out.println ("Password:" + get(i).getPasswd());
System.out.println ("Region:" + get(i).getAddress());
}
} } catch (Exception e) {
System.out.println("SQL Error:" + e.getMessage());
} finally { // End objects in reverse order (close equal to the number of objects)
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} } catch (SQLException e) {
e.printStackTrace();
} // End catch
}// End of try
} // Exit main method
}
It's a basic question.
The reason the questioner finds it difficult is because the array is static, so you need to specify a size.
The question is how to get row numbers.
If you look at the reset set, there is the last method. Move the cursor to the last item. After the last call, getRow counts and return to beforeFirst mode.
This way you'll be able to do what you want.
© 2024 OneMinuteCode. All rights reserved.