Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package emailspammer.sql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL
- {
- public static String username;
- public static String password;
- public static String database;
- public static String host;
- public static int port;
- public static Connection con;
- public static void connect()
- {
- username = "root";
- password = "";
- database = "test";
- host = "127.0.0.1";
- port = 3306;
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- }
- catch (SQLException e)
- {
- System.out.println("Die Verbindung zur Datenbank ist fehlgeschlagen!");
- }
- }
- public static void execute(String qry)
- {
- try
- {
- Statement st = con.createStatement();
- st.execute(qry);
- st.close();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry)
- {
- try
- {
- return con.createStatement().executeQuery(qry);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
- public static void close()
- {
- try
- {
- con.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement