Skip to content

Instantly share code, notes, and snippets.

@ron623
Last active January 20, 2023 19:33
Show Gist options
  • Save ron623/27888f35203208f4c45e to your computer and use it in GitHub Desktop.
Save ron623/27888f35203208f4c45e to your computer and use it in GitHub Desktop.
health
package health;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField userName;
private JPasswordField password;
// 画面名称(画面遷移で使用)
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane
.setLayout(new FormLayout(new ColumnSpec[] {
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
ColumnSpec.decode("default:grow"), }, new RowSpec[] {
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC, }));
JLabel lblNewLabel = new JLabel("New label");
contentPane.add(lblNewLabel, "6, 4, right, default");
userName = new JTextField();
contentPane.add(userName, "8, 4, left, default");
userName.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("New label");
contentPane.add(lblNewLabel_1, "6, 6, right, default");
password = new JPasswordField();
password.setColumns(10);
contentPane.add(password, "8, 6, left, default");
JButton btnNewButton = new JButton("登録");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// user,passに入っているtextを取り出す
String user = userName.getText();
char[] passArray = password.getPassword();
String pass = charArrayToString(passArray);
// user,pass未入力時return
boolean chk = nullChk(user, pass);
if (chk == false) {
return;
}
// DB接続、検索
try {
connect(user, pass);
} catch (SQLException e1) {
// TODO 自動生成された catch ブロック
JOptionPane.showMessageDialog(null, "DB接続エラー!");
e1.printStackTrace();
}
}
});
contentPane.add(btnNewButton, "8, 8, center, default");
}
/*
* char[] → String
*/
public String charArrayToString(char[] array) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; i++) {
sb.append(array[i]);
}
String str = sb.toString();
return str;
}
/**
* 未入力ちぇっく
*/
public boolean nullChk(String user, String pass) {
boolean chk = false;
if ("".equals(user)) {
JOptionPane.showMessageDialog(null, "userが未入力です");
return false;
}
if ("".equals(pass)) {
JOptionPane.showMessageDialog(null, "passが未入力です");
return false;
}
return true;
}
/**
* Connect Db
*/
public void connect(String user, String pass) throws SQLException {
// コネクションを取得する
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:XE", // URL
"system", // ユーザID
"manager" // パスワード
);
// SQL文を表すjava.sql.Statementオブジェクトを作成
Statement stmt = conn.createStatement();
StringBuilder sb = new StringBuilder();
sb.append("select * from ARS_USER ");
sb.append(" WHERE ");
sb.append("MEMBER_ID = ");
sb.append("'");
sb.append(user);
sb.append("'");
String sql = sb.toString();
// データベースに問い合わせ
ResultSet result = stmt.executeQuery(sql);
// データ有無(true:あり/ false:なし)
boolean isExists = result.next();
//
if (isExists == true) {
// while (result.next()) {
String pwd = result.getString("PASS");
if (pwd.equals(pass)) {
// テキストボックスに入力された値をメッセージ表示する
JOptionPane.showMessageDialog(null, "照合成功: ");
// healthcheck画面へ遷移
HealthCheck hc = new HealthCheck();
hc.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "照合失敗: \n passが違います");
return;
}
// }
} else {
JOptionPane.showMessageDialog(null, "ログインエラー!: \n user: " + user
+ "は登録されていません。");
return;
}
}
/*
* 画面遷移
*/
public void panelChange(JPanel jp,String str) {
String name = jp.getName();
// パネル名により画面遷移先を変える
HealthCheck.getFrames();
}
}
@Dyee2
Copy link

Dyee2 commented Jan 20, 2023

Yes to find all the most necessary information about bio identical supplements nowadays can absolutely every person. I can tell you that if you go to this site exactly here, you will be able to find for yourself the most reliable information about all the bio identical supplements that now only can be available and at this moment in time. It seems to me that this is the best option at all that there is. I can absolutely tell you that this website https://valhallavitality.com/blog/bioidentical-hormones-clinic-for-your-health has the best clinic that can pick you up the best course of bio identical supplements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment