import java.awt.GridLayout; import java.sql.*; import javax.swing.*; public class Display extends JApplet{ private Connection con; public Display() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager.getConnection("jdbc:mysql://localhost/datatest","root","monoblos2537"); Statement s = con.createStatement(); setLayout(new GridLayout(0,5)); ResultSet rec = s.executeQuery("select * from mymusic"); JOptionPane.showMessageDialog(null, rec); JOptionPane.showMessageDialog(null, "Wellcome to database."); while((rec!=null) && (rec.next())){ add(new JLabel(rec.getString("id"))); add(new JLabel(rec.getString("artist"))); add(new JLabel(rec.getString("album"))); add(new JLabel(rec.getString("title"))); add(new JLabel(rec.getString("year"))); } con.close(); } catch (SQLException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, "Error"); } catch(ClassNotFoundException e){ JOptionPane.showMessageDialog(null, "Not Found"); } } }
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test Database</title> </head> <body> <applet code = "Display.class" width = 450 height = 300 archive = "mysql-connector-java-5.1.18-bin.jar,sqljdbc4.jar" > </applet> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง