Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.edu.tutorial.trabalho;
- import java.sql.Connection;
- public class ConexaoUtil {
- private static ConexaoUtil conexaoUtil;
- public static ConexaoUtil getInstance() {
- if (conexaoUtil == null) {
- conexaoUtil = new ConexaoUtil();
- }
- return ConexaoUtil;
- }
- public Connection getConnection() throws ClassNotFoundException, SQLException {
- Class.forName("com.mysql.jdbc.Driver");
- return DriverManager.getConnection("jdbc:mysql://localhost:3306/nome_do_banco","root","root"); // (servidor que vai rodar o mysql, usuario, senha).
- }
- public static void main(String[]args) {
- try {
- System.out.println(getInstanc().getConnection());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement