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.SQLException;
- import java.sql.Statement;
- public class DB {
- private static DB instance = new DB();
- public static final String URL = "jdbc:mysql://127.0.0.1:3306/user";
- public static final String USER = "root";
- public static final String PASSWORD = "";
- public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
- public DB() {
- try {
- Class.forName(DRIVER_CLASS);
- }
- catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public Connection createConnection() {
- Connection connection = null;
- try {
- connection = DriverManager.getConnection(URL, USER, PASSWORD);
- } catch (SQLException e) {
- System.out.println("ERROR: Unable to Connect to Database.");
- }
- return connection;
- }
- public static Connection getConnection() {
- return instance.createConnection();
- }
- public void scrivi(String user,String pass,String email) throws SQLException
- {
- Connection connection = null;
- Statement statement = null;
- try {
- connection = DB.getConnection();
- statement = connection.createStatement();
- statement.executeUpdate("INSERT into Users (user,password,email) values('"+user+"','"+pass+"','"+email+"')");
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement