Hi All,
I am new to use of database in Java. I am trying to write a simple java application which connects to my Database and sends some query and retrieves the output.
I have downloaded MariaDB and then created a database named iff and created tablespaces which has some information.
I have also downloaded JDBC driver from MariaDB site "mariadb-java-client-1.1.3" and also imported this JAR file in my project library in Eclipse.
Im facing hardtime connecting to my database. I have tried some Syntaxes available in Websites but nothing worked.
Below is my program which DID NOT connect ,
Please help me how to connect to database and run some basic queries.
FYI
Database Name iff
Location of Database Installed (C:\Program Files (x86)\Common Files\MariaDBShared\HeidiSQL)
JDBC driver Name mariadb-java-client-1.1.3 (Jar File)
Location of JDBC D:\JDBC
import java.sql.Connection;
import java.sql.DriverManager;
import javax.sql.*;
public class UserService {
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "jdbc:mysql://localhost:3306/";
String dbName = "iff";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}