Advertisement
Guest User

Untitled

a guest
Mar 17th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. /*
  9.  * To change this license header, choose License Headers in Project Properties.
  10.  * To change this template file, choose Tools | Templates
  11.  * and open the template in the editor.
  12.  */
  13. /**
  14.  *
  15.  * @author Patryk
  16.  */
  17. public class MySQLDatabase {
  18.     public static void connection()
  19.     {
  20.         try {
  21.             Class.forName("com.mysql.jdbc.Driver");
  22.         } catch (ClassNotFoundException e){
  23.             e.printStackTrace();
  24.         }
  25.     }
  26.     public static void connectionMySQL(){
  27.         connection();
  28.         String host = "jdbc:mysql://localhost/users";
  29.         String username = "root";
  30.         String password = "";
  31.         PreparedStatement zapytanieMySQL = null; //Sprawdzic co to jest
  32.         //ResultSet wynik = null;
  33.         try {
  34.             Connection polaczenie = DriverManager.getConnection(host, username, password);
  35.            zapytanieMySQL = polaczenie.prepareStatement("Insert into users (Login, Password) value (?,?)");
  36.            zapytanieMySQL.setString(1, "Jakubian");
  37.            zapytanieMySQL.setString(2, "Superowatosci");
  38.             System.out.println("Works :) ");
  39.            
  40.            
  41.            
  42.             zapytanieMySQL.execute();
  43.         } catch (SQLException e){
  44.                 e.printStackTrace();
  45.             }
  46.         }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement