-
Notifications
You must be signed in to change notification settings - Fork 0
/
Words
33 lines (31 loc) · 1.04 KB
/
Words
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.sql.*;
import javax.swing.JOptionPane;
public class CowsNBulls {
public static void main (String[] args){
for(int i = 0; i<= 10; i++ ){
String wd = getWord();
System.out.println(wd);
}
}
private static String getWord(){
String word = query("select * from words order by rand() limit 1;","word");
return word;
}
static String query(String statement, String ret) {
String str = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/cowsbulls", "root", "");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(statement);
if (rs.next()) {
str = rs.getString(ret);
}
st.close();
conn.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "" + e.getMessage());
}
return str;
}
}