Answers for "how to use mysql with java"

13

java connect to mysql

import java.sql.*;  
class MySqlConn{  
    public static void main(String args[]){  
        try{  
            Class.forName("com.mysql.cj.jdbc.Driver");  
            Connection conn = DriverManager.getConnection("jdbc:mysql://
            localhost:3306/databasename","username","password");  
            Statement stmt = conn.createStatement();  
            ResultSet rs = stmt.executeQuery("select * from emp");    
            con.close();  
        }catch(Exception ex){
            System.out.println(ex);
        }  
    }
}
Posted by: Guest on May-22-2020
0

conexion a mysql java

String Url="jdbc:mysql://" + /* IP o Dominio de la base de datos*/ +"/" + /*La base de datos*/;
//Importante encapsular la conexión en un 'try', puede dar errores.
try {
	BD_Conexion = DriverManager.getConnection(Url, /* Usuario */, /* Contraseña */);
}catch(SQLException SQLError){
  //Asegurate de que no da errores la conexion.
}
Posted by: Guest on January-30-2021

Code answers related to "how to use mysql with java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language