Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class db {
- public String result;
- public String request (String col, String nick) throws SQLException {
- String url = "jdbc:mysql://localhost:3306/JavaRot";
- // Access driver from jar file.
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e1) {
- // TODO insert error msgs.
- e1.printStackTrace();
- }
- Connection con = DriverManager.getConnection(url,"JavaRot", "M@H4jr");
- // Query creation.
- //db dbObject = new db("SELECT hosts FROM users_GTAnet WHERE nick = '" + sender + "'");
- try{PreparedStatement statement = con.prepareStatement("SELECT " + col + " FROM users_GTAnet WHERE nick = '" + nick + "'");
- // Set var to exec query.
- ResultSet rs = statement.executeQuery();
- // Fetch each row from the result set
- while (rs.next()) {
- // Get the data from the row using the column name
- result = rs.getString(col);
- }
- }catch (SQLException e) {}
- public String result;
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement