I am having problems connecting to the mysql databse from a Java application in 
Windows 2K, I am using JDBC and have the mySQL odbc software installed.  I am running 
mysql from the command line prompt in Windows 2k. I fear I may be doing something 
wrong, if anyone has a step by step solution, i would be so grateful. This is the code 
in my Java application that i am having problems with. Becuase of this problem I am 
having to use Microsoft access, and can connect to that no problem. What do i need to 
change to make it compatable with myswl, i have been trying fro ages but had no 
luck.Any help with this would be more than helpful and appreciated.

   usernameString = nameField.getText();
   passwordString = passwordField.getText();
   
   Connection connection = null;

   String url = "jdbc:odbc:FYP";  
   String username = "anonymous";
   String password = "guest";  
 
    // Load the driver to allow connection to the database
     try
     {
     Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

     connection = DriverManager.getConnection(url, username, password );
     } 
     
     catch ( ClassNotFoundException cnfex ) 
     {
     System.err.println("Failed to load JDBC/ODBC driver." );
     cnfex.printStackTrace();
     System.exit( 1 );  // terminate program
     }
     
     catch ( SQLException sqlex )
     {
     System.err.println( "Unable to connect" );
     sqlex.printStackTrace();
     } 

     Statement statement;
     ResultSet result;
 
   
     try 
     { 
      System.out.println(usernameString);
      System.out.println(passwordString);
      
      statement = connection.createStatement();
      result = statement.executeQuery("SELECT * FROM userProfile WHERE username = '" + 
usernameString + "'");
    
     while (result.next())
     {
        text = result.getString("adminlevel");
        System.out.println(text);
     }
    
     statement.close();
      connection.close();      
}

Reply via email to