-
Notifications
You must be signed in to change notification settings - Fork 0
/
JDBCConnection.java
39 lines (33 loc) · 1.11 KB
/
JDBCConnection.java
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
34
35
36
37
38
39
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.sql.*;
/**
* Write a description of class JDBCConnection here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class JDBCConnection extends Actor
{
Connection getConnection() {
//See your driver documentation for the proper format of this string :
String DB_CONN_STRING = "jdbc:mysql://54.235.83.253:3306/WordsDB";
//Provided by your driver documentation. In this case, a MySql driver is used :
String DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
String USER_NAME = "sjsu202";
String PASSWORD = "sjsu";
Connection result = null;
try {
Class.forName(DRIVER_CLASS_NAME).newInstance();
}
catch (Exception ex){
System.out.println("Check classpath. Cannot load db driver: " + DRIVER_CLASS_NAME);
}
try {
result = DriverManager.getConnection(DB_CONN_STRING, USER_NAME, PASSWORD);
}
catch (SQLException e){
System.out.println( "Driver loaded, but cannot connect to db: " + DB_CONN_STRING);
}
return result;
}
}