Conectar java con mysql

Page 1

package otrodb; import java.sql.*; public static static static static public

class OtroDB { String bd = "alumnos"; String login = "root"; String password = ""; String url = "jdbc:mysql://localhost/"+bd; static void main(String[] args) throws Exception { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection(url,login,password); if (conn != null) { System.out.println("Conexi贸n a base de datos "+url+" ... Ok"); conn.close(); } } catch(SQLException ex) { System.out.println("Hubo un problema al intentar conectarse con la base de datos "+url); } catch(ClassNotFoundException ex) { System.out.println(ex); } } }


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.