I am trying to connect to a mySQL database.I set it up on the ODBC after installing myODBC. I am attempting to dump all the tables in the database through a executequery command and than attempting to run a script with the \. command. Here is my code, but for some rerason I am running into errors with the executequery commands. Any help would be greatly appreciated.
//connection instance
Connection dbConnection_MySQL;
//get URL for mySQL connection
String urlMySQL = "jdbc
dbc:WAG";
//load driver for odbc to access MS Access and MySQL
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//make connection to database
dbConnection_MySQL=DriverManager.getConnection (urlMySQL,"root","paul"); //mysql
//**1 This first section drops the tables out of the database
//create a statment
Statement statement=dbConnection_MySQL.createStatement();
//make query
String drop= "Drop Table If Exists ";
for(int i=0;i<table.length;i++) //add all table names
{if(i==(table.length)-1)
drop=drop+"`" +table+"`;";
else
drop=drop+"`" +table+"`,";
}
System.out.println(drop);
//run sql statment
ResultSet DropTables = statement.executeQuery(drop);
//**2 Now we run the scipt to create all the database structure
//set up sql file for the creation of the tables
String createtables ="\\. c:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\watson2.sql";
System.out.println(createtables);
ResultSet AddTables = statement.executeQuery(createtables);
I keep getting jdbc odbc errors. If the two executeQuery commands are removed program runs smoothly, without updating the databases of course.
Paul
//connection instance
Connection dbConnection_MySQL;
//get URL for mySQL connection
String urlMySQL = "jdbc
//load driver for odbc to access MS Access and MySQL
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//make connection to database
dbConnection_MySQL=DriverManager.getConnection (urlMySQL,"root","paul"); //mysql
//**1 This first section drops the tables out of the database
//create a statment
Statement statement=dbConnection_MySQL.createStatement();
//make query
String drop= "Drop Table If Exists ";
for(int i=0;i<table.length;i++) //add all table names
{if(i==(table.length)-1)
drop=drop+"`" +table+"`;";
else
drop=drop+"`" +table+"`,";
}
System.out.println(drop);
//run sql statment
ResultSet DropTables = statement.executeQuery(drop);
//**2 Now we run the scipt to create all the database structure
//set up sql file for the creation of the tables
String createtables ="\\. c:\\Program Files\\MySQL\\MySQL Server 4.1\\bin\\watson2.sql";
System.out.println(createtables);
ResultSet AddTables = statement.executeQuery(createtables);
I keep getting jdbc odbc errors. If the two executeQuery commands are removed program runs smoothly, without updating the databases of course.
Paul