###前提・実現したいこと
mysqlに入っているloginテーブルのjikan3をlblNewLabel_1に出力したい
###発生している問題・エラーメッセージ
###該当のソースコード
public class Kyuuryoumeisai extends JFrame { String hoge2; private JPanel contentPane; static Connection connect =null; static java.sql.Statement stmt =null; static ResultSet relt=null; public Kyuuryoumeisai(String hoge){ hoge2=hoge; try { Kyuuryoumeisai frame = new Kyuuryoumeisai(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } public Kyuuryoumeisai() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); setLocation(600,300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel label = new JLabel("\u52E4\u52D9\u6642\u9593"); label.setFont(new Font("HGP創英角ゴシックUB", Font.PLAIN, 18)); label.setBounds(46, 57, 134, 50); contentPane.add(label); JLabel lblNewLabel = new JLabel("\u6642\u9593"); lblNewLabel.setFont(new Font("MS UI Gothic", Font.PLAIN, 20)); lblNewLabel.setBounds(287, 89, 76, 50); contentPane.add(lblNewLabel); String jikan = null; try{ Class.forName("com.mysql.jdbc.Driver"); connect= DriverManager.getConnection("jdbc:mysql://localhost:3306/login01","root","root"); stmt = connect.createStatement(); String sql = ("SELECT jikan3 FROM login where id= "+hoge2+""); ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ jikan = rs.getString("jikan3"); } } catch(Exception e){ System.out.println("a"); e.printStackTrace(); } JLabel lblNewLabel_1 = new JLabel(jikan); lblNewLabel_1.setFont(new Font("MS UI Gothic", Font.PLAIN, 25)); lblNewLabel_1.setBounds(183, 88, 70, 50); contentPane.add(lblNewLabel_1); } }
###試したこと
###補足情報(言語/FW/ツール等のバージョンなど)
エクリプス
回答1件
あなたの回答
tips
プレビュー