I need to connect to mySQL database from my Scala code. i have the below code to make the connection. i am importing the java packages to connect to database from scala and i am using the Drivermanager to make the connection. i have written one class and one method inside it for make the conection and i am extending and using it from my object.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
class DBConnectionClass {
val user = "root"
val pass = "admin"
val url = "jdbc:mysql://172.16.40.5/scalatest"
def readDataBase() = {
try {
Class.forName("com.mysql.jdbc.Driver")
val connection: Connection = DriverManager.getConnection(url, user, pass);
}
catch {
case _: Throwable => println("Could not connect to database")
}
}
}
and in my running scala object is,
object TestAppMain {
def main(args: Array[String]){
val DBconnObject = new DBConnectionClass
DBconnObject.readDataBase
println("Check DB Is connected or not")
}
}
but it is throwing an exception that coud not connect to data base.. anybody can help me...thanx in advance