Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class mySQL {
- public static Connection Connection = null;
- public static void createConnection() {
- try {
- String driverName = "org.gjt.mm.mysql.Driver";
- Class.forName(driverName);
- String serverName = "localhost"; // the database
- String mydatabase = "database"; // the database name
- String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
- String username = "username"; // The database username
- String password = "password"; // The database password
- Connection = DriverManager.getConnection(url, username, password);
- System.out.println("Now connected to the SQL server");
- } catch (ClassNotFoundException e) {
- System.out.println("Driver class not found.");
- } catch (SQLException e) {
- System.out.println("Error connecting to the SQL server");
- }
- }
- public static void destroyConnection() {
- try {
- if(Connection != null) Connection.close();
- } catch (Exception e) {
- }
- }
- public static void executeQuery(String mquery) {
- try {
- Statement stmt = Connection.createStatement();
- stmt.executeUpdate(mquery);
- stmt.close();
- } catch (Exception e) { e.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement