@@ -29,6 +29,21 @@ | |||
<!-- The "lib" classifier is optional, but it gives you a MUCH smaller jar which is all you need as a Java library --> | |||
<classifier>lib</classifier> | |||
</dependency> | |||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> | |||
<dependency> | |||
<groupId>mysql</groupId> | |||
<artifactId>mysql-connector-java</artifactId> | |||
<version>8.0.24</version> | |||
</dependency> | |||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> | |||
<!-- https://projectlombok.org/--> | |||
<dependency> | |||
<groupId>org.projectlombok</groupId> | |||
<artifactId>lombok</artifactId> | |||
<version>1.18.20</version> | |||
<scope>provided</scope> | |||
</dependency> | |||
</dependencies> |
@@ -1,14 +1,22 @@ | |||
package be.syntra; | |||
import be.syntra.dao.QuoteDao; | |||
import be.syntra.daoimpl.QuoteDaoImpl; | |||
import be.syntra.model.Quote; | |||
import com.github.ricksbrown.cowsay.Cowsay; | |||
public class App { | |||
public static void main(String[] args) { | |||
QuoteDao quoteDao = new QuoteDaoImpl(); | |||
Quote quote = quoteDao.getRandomQuote(); | |||
String message = "Hello from Java!"; | |||
String cow = "dragon"; | |||
String[] cowArgs = new String[]{"-f", cow, "Jordi Says: " + message}; | |||
String[] cowArgs = new String[]{"-f", cow, quote.getAuthor() +" Says: " + quote.getQuote()}; | |||
String result = Cowsay.say(cowArgs); | |||
System.out.println(result); | |||
} |
@@ -0,0 +1,46 @@ | |||
package be.syntra.daoimpl; | |||
import be.syntra.dao.QuoteDao; | |||
import be.syntra.model.Quote; | |||
import java.sql.*; | |||
public class QuoteDaoImpl implements QuoteDao { | |||
private static String url = "jdbc:mysql://ID109462_crud.db.webhosting.be:3306/ID109462_crud"; | |||
private static String usr = "ID109462_crud"; | |||
private static String pass = "code4croissants"; | |||
@Override | |||
public Quote getRandomQuote() { | |||
String sql = "SELECT * FROM jordiquotes ORDER BY RAND() LIMIT 1"; | |||
try (Connection con = DriverManager.getConnection(url, usr, pass); | |||
PreparedStatement ps = con.prepareStatement(sql)) { | |||
try (ResultSet rs = ps.executeQuery()) { | |||
if (rs.next()) { | |||
Quote quote = new Quote(); | |||
quote.setId(rs.getInt("id")); | |||
quote.setAuthor(rs.getString("author")); | |||
quote.setQuote(rs.getString("quote")); | |||
quote.setLikes(rs.getInt("likes")); | |||
quote.setDislikes(rs.getInt("dislikes")); | |||
return quote; | |||
} | |||
} catch (SQLException throwables) { | |||
throwables.printStackTrace(); | |||
} | |||
} catch (SQLException throwables) { | |||
throwables.printStackTrace(); | |||
} | |||
return null; | |||
} | |||
@Override | |||
public void likeQuote(Quote quote) { | |||
} | |||
@Override | |||
public void dislikeQuote(Quote quote) { | |||
} | |||
} |
@@ -1,22 +0,0 @@ | |||
package be.syntra.daoimpl; | |||
import be.syntra.dao.QuoteDao; | |||
import be.syntra.model.Quote; | |||
public class QuoteImpl implements QuoteDao { | |||
@Override | |||
public Quote getRandomQuote() { | |||
return null; | |||
} | |||
@Override | |||
public void likeQuote(Quote quote) { | |||
} | |||
@Override | |||
public void dislikeQuote(Quote quote) { | |||
} | |||
} |
@@ -1,9 +1,12 @@ | |||
package be.syntra.model; | |||
import lombok.Data; | |||
@Data | |||
public class Quote { | |||
private int id; | |||
private int author; | |||
private int quote; | |||
private String author; | |||
private String quote; | |||
private int likes; | |||
private int dislikes; | |||