I'm trying to make the program read the "Entity.sql" File and then execute it to make it run in phpmyadmin. I did used a mysql connector to link netbeans to mysql and then it should used the Connection for phpmyadmin to execute the Statement (Entity.sql)
The Entity.sql file contains as sql Statement:
CREATE DATABASE IF NOT EXISTS Student
The problem is that it's not working and it's giving me this error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
here is my entire code:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.*;
import java.io.*;
import java.util.*;
public class SQLConnecter {
private Connection con;
private Statement st;
private ResultSet rs;
public SQLConnecter(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/","root","");
st = con.createStatement();
}
catch(Exception ex){
System.out.println("Error:"+ ex);
}
}
public void getData(){
try{
Scanner infile = new Scanner(new File("Entity.sql"));
String sql = infile.next();
while(infile.hasNext()){
st.executeUpdate(sql);
}
infile.close();
}
catch(Exception ex){
System.out.println(ex);
}
}
public static void main(String args[]){
SQLConnecter connect = new SQLConnecter();
connect.getData();
}
}
I want the program to first
1- Read the Entity.sql file
2- Execute the file into phpmyadmin
Can someone please help me to solve this?