Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package gui;
- /**
- *
- * @author ilmarir
- */
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.*;
- import java.awt.*;
- import java.sql.*;
- public class Gui {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws SQLException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.err.println("JDBC-ajurin lataus epäonnistui");
- System.exit(-1); // lopetus heti virheen vuoksi
- }
- final String URL = "jdbc:mysql://10.114.32.18/tilanvaraus";
- final String USERNAME = "tilanvaraus";
- final String PASSWORD = "mysteerikuutioR5";
- Connection conn =DriverManager.getConnection(URL, USERNAME, PASSWORD);
- Statement stmt = conn.createStatement();
- String query = "select name FROM Room";
- ResultSet rs = stmt.executeQuery(query);
- String[] nimet = new String[20];
- int i = 0;
- while (rs.next()) {
- nimet[i] = rs.getString("name");
- i++;
- }
- rs.close();
- stmt.close();
- conn.close();
- JList list;
- JFrame f=new JFrame();//creating instance of JFrame
- JPanel p = new JPanel();
- //JButton b=new JButton("click");//creating instance of JButton
- //b.setBounds(130,100,100, 40);//x axis, y axis, width, height
- //f.add(b);//adding button in JFrame
- list = new JList(nimet); //data has type Object[]
- //list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
- //list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
- //list.setVisibleRowCount(-1);
- //JScrollPane listScroller = new JScrollPane(list);
- //listScroller.setPreferredSize(new Dimension(250, 80));
- f.add(p);
- p.add(list);
- f.pack();
- //f.setSize(600,700);//400 width and 500 height
- f.setLayout(null);//using no layout managers
- f.setVisible(true);//making the frame visible
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement