Código:
public class Coneccion { public static java.sql.Connection getMySqlConnection(String database, String servername, int port, String username, String password){ DataSource ds=null; try{//javax.naming.InitialContext ctx = new javax.naming.InitialContext(); Class.forName("org.gjt.mm.mysql.Driver").newInstance(); System.out.println("Class for name"); //ds = (DataSource)ctx.lookup("java:comp/env/jdbc/MySQLDB"); } catch(Exception ex) { System.out.println("Error: "+ex); return null; } java.sql.Connection conn; java.sql.Statement stmt; try{System.out.println("inicio"); String url="jdbc:mysql://localhost:3306/DatosPersonales"; conn=DriverManager.getConnection(url,username,password); System.out.println("Conexion Satisfactoria"); return conn; } catch(SQLException ex) { System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); return null; } } }