java database connectivity with mysql code example
Example 1: 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);
}
}
}
Example 2: python and mysql connectivity
import pymysql
db = pymysql.connect("database_host","username","password","database_name")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print ("Database version : {0}".format(data))
db.close()