Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package agenda;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author labsim
- */
- public class MyConnection {
- private Connection con;
- Statement stmt;
- String url = "jdbc:mysql://127.0.0.1:3306/agenda";
- String user = "root";
- String password = "aluno@etep";
- String nome = "Marcos";
- String area = "11";
- String num = "2562-5541";
- public MyConnection() throws ClassNotFoundException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url, user, password);
- stmt = con.createStatement();
- System.out.println("Conectado com sucesso!");
- } catch (SQLException ex) {
- Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- stmt.execute("INSERT INTO contato VALUES (NULL,'" + nome + "','" + area + "','" + num + "');");
- } catch (SQLException e) {
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement