mysql and java

2002-02-25 Thread Bill Fogarty

Hi,

Does anyoone know how to connect to mysql from a Java application in windows 2k?
Any help would be greatly apppreciated. I may be writing to the wrong list, anyone got 
any suggestions of where i could get help with this online.

Cheers,
Bill



mySQl JDBC connectivity in Windows.

2002-02-21 Thread Bill Fogarty

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();  
}