Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL driver, SQL injection, eclipse in gitignore, bumb version. #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/target/
# eclipse project file
.settings/
.classpath
.project
/target/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lu.r3flexi0n</groupId>
<artifactId>BungeeOnlineTime</artifactId>
<version>7.0</version>
<version>7.1</version>
<packaging>jar</packaging>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public MySQL(String host, int port, String database, String username, String pas

@Override
public void openConnection() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.cj.jdbc.Driver");
setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
}
}
18 changes: 11 additions & 7 deletions src/main/java/lu/r3flexi0n/bungeeonlinetime/database/SQL.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lu.r3flexi0n.bungeeonlinetime.database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -49,24 +50,27 @@ public void updateOnlineTime(UUID uuid, String name, long time) throws Exception
}

public OnlineTime getOnlineTime(UUID uuid) throws Exception {
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE uuid = '" + uuid + "';";
return get(sql);
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE uuid = ?;";
PreparedStatement p = connection.prepareStatement(sql);
p.setString(1, uuid.toString());
return get(p);
}

public OnlineTime getOnlineTime(String name) throws Exception {
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE name = '" + name + "';";
return get(sql);
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE name = ?;";
PreparedStatement p = connection.prepareStatement(sql);
p.setString(1, name);
return get(p);
}

private OnlineTime get(String sql) throws Exception {
private OnlineTime get(PreparedStatement statement) throws Exception {
if (isClosed()) {
openConnection();
}

OnlineTime onlineTime = null;

Statement statement = connection.createStatement();
ResultSet resultset = statement.executeQuery(sql);
ResultSet resultset = statement.executeQuery();
if (resultset.next()) {

UUID uuid = UUID.fromString(resultset.getString("uuid"));
Expand Down