Don't like ads? PRO users don't see any ads ;-)

Conexion MySQL con mydb

By: simplesroger on May 8th, 2012  |  syntax: Java  |  size: 0.61 KB  |  hits: 118  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package unsch.efpis.ConexionDB;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8.  *
  9.  * @author sin_querer
  10.  */
  11. public class Conexion {
  12.     private static Connection cn = null;
  13.     private static String URL = "jdbc:mysql://localhost:3306/mydb";
  14.     private static String usuario = "root";
  15.     private static String contrasena = "123456";
  16.    
  17.     public static Connection getConexion() throws SQLException {
  18. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  19.         cn = DriverManager.getConnection(URL, usuario, contrasena);
  20.         return cn;
  21.     }
  22. }