-1
public static ArrayList<User_Database> getUsername() {
ArrayList<User_Database> list_Username = new ArrayList<User_Database>();
try {
Class.forName(driver);
String sql = "SELECT user_name FROM users";
Connection connect = DriverManager.getConnection(url, user, password);
Statement state = connect.createStatement();
ResultSet rs = state.executeQuery(sql);
while (rs.next()) {
String user_name = rs.getString("user_name");
User_Database userDB = new User_Database(user_name);
list_Username.add(userDB);
System.out.printf(" %s \n", user_name);
}
rs.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
return list_Username;
}
public static void createNewUser(User_Database us) {
getAllUser();
try {
Class.forName(driver);
Connection connect = DriverManager.getConnection(url, user, password);
Statement state = connect.createStatement();
String sql = "INSERT INTO users VALUES (0, '" + us.user_name + "' , '" + us.user_password + "' , '"
+ us.email + "') ";
if (getAllUser().equals(us.user_name)) {
System.out.println("Username not available");
} else {
state.executeUpdate(sql);
state.close();
System.out.println("Insert Database Success");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
}
あなたのコードにあなたの心を入れてください。 –
私はちょうどamaturだと教えてください –