Hello guys I’m making an application that accesses MySQL & MsSQL databases that fiddles about with them and depending which one it accessed prints out the tables, and the part of the code that does that is this:
Connection con = DriverManager.getConnection(dbUrl, userName,password);
Statement stmt = con.createStatement();
ResultSet rs;
if (driverCN.startsWith("com.mysql")) { // For MySQL.
rs = stmt.executeQuery("Show Tables");
} else { // For MsSQL
rs = stmt.executeQuery("??????");
}
// Displays the remaining Database tables.
System.out.println("\nThese are the remaining Database Tables:\n");
while (rs.next()) {
String db = rs.getString(1);
System.out.println(db);
}
Now what I want to know, is how do I make this work for MsSQL as well, what kind of query do I execute and will the results be passed onto my result set? ( this works perfectly for MySQL database, I simply don’t have MsSQL database to test this on just yet. Thank you in advance!
SQL Server 2005 or 2008:
SQL Server 2000: