Java Reference
In-Depth Information
For example, you will get the following error messages if the user does not exist or owns some object.
ERROR: DROP USER: user " user_name " does not exist
ERROR: DROP USER: user " user_name " owns database " name ", cannot
be removed
Listing 24-2 displays the JDBC code to create and delete users.
Listing 24-2: Working with Users
package jdbc_bible.part2;
import java.sql.*;
import sun.jdbc.odbc.JdbcOdbcDriver;
public class UserManager {
static String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
static String url = "jdbc:odbc:dummyDB";
static String SQL_UserDelete =
"DROP USER ";
public UserManager(){
registerDriver();
}
public void registerDriver(){
try
{
Class.forName(jdbcDriver);
DriverManager.registerDriver(new JdbcOdbcDriver());
}
catch(ClassNotFoundException e){
System.err.print(e.getMessage());
}
catch(SQLException e){
System.err.println(e.getMessage());
}
}
public void createUser(String username, String password) {
Connection con;
Statement stmt;
try
{
Search WWH ::




Custom Search