In my code, My finally output, is not like in MySQl console output:
public class d3 {
Connection con;
String dbName = "mydb";
String dbUsername = "root";
String dbPassword = "2323";
String dbUrl = "jdbc:mysql://localhost/";
public d3() {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Find database successfuly");
} catch (Exception e) {
System.err.println("Unable to find and load driver");
System.exit(1);
}
}
public void connectToDB() {
try {
con = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
System.out.println("Connect to database succesfully");
} catch (SQLException e) {
System.out.println("Can not connect to database");
System.exit(1);
}
}
public void excuteSQL() {
String sqlString1 = "use mydb";
String sqlString2 = "show tables";
String result;
try {
Statement st1 = con.createStatement();
ResultSet result1 = st1.executeQuery(sqlString1);
while(result1.next()){
result = result1.getString(dbName);
System.out.println(result1);
}
} catch (SQLException sqle) {
System.out.println("Can not excute sql statement");
}
}
public static void main(String[] args) {
d3 ddd = new d3();
ddd.connectToDB();
ddd.excuteSQL();
}
}
My output:
Find database successfuly
Connect to database succesfully
Result set representing update count of 0
But, I want to be like this:
Find database successfuly
Connect to database succesfully
Database changed // this is shown in console
I am going step by step and comparing outputs from mysql console and my IDE console, For example, I want to see "Database changed" message after execute "use mydb" statement.