Answers for "mysql database in java"

SQL
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

mysqli database

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");

/* Vérification de la connexion */
if (mysqli_connect_errno()) {
    printf("Échec de la connexion : %s\n", mysqli_connect_error());
    exit();
}

/* Retourne le nom de la base de données courante */
if ($result = $mysqli->query("SELECT DATABASE()")) {
    $row = $result->fetch_row();
    printf("La base de données courante est %s.\n", $row[0]);
    $result->close();
}

/* Change la base de données en "world" */
$mysqli->select_db("world");

/* Retourne le nom de la base de données courante */
if ($result = $mysqli->query("SELECT DATABASE()")) {
    $row = $result->fetch_row();
    printf("La base de données courante est %s.\n", $row[0]);
    $result->close();
}

$mysqli->close();
?>
Posted by: Guest on February-23-2020

Code answers related to "mysql database in java"

Code answers related to "SQL"

Browse Popular Code Answers by Language