Link to home
Start Free TrialLog in
Avatar of wdunski
wdunski

asked on

Convert this simple Java prog to C# : I'm trying to learn.

Hello experts,
I've recently become very interested in C#.
I purchased a few books on the subject and plan to learn it.

Anyhow, what's a better way to learn then by example and pracitce?

I would be very greatful if someone could convert the following Java program to a C# program.

*******CODE STARTS HERE*************

package woj.mysql;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * @author Wojciech Dunski
 *
 */
public class reloadMaster {
      
      private ResultSet rs;
      private static Connection conn;
    private Statement stat;
   
    public reloadMaster(){
          try{
                conn = getConnection();
          }
          catch (SQLException e)
        {  
           e.printStackTrace();
        }
          catch(IOException ioe){
                ioe.printStackTrace();
          }
    }
   
    public static Connection getConnection()
          throws SQLException, IOException
          {
          System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/inventory";
        String username = "root";
        String password = "sunrise";
        return DriverManager.getConnection(url, username, password);
          }
   
    public void executeQueries(){
          boolean done;
          try{             
                String query = "DELETE masterInventory from masterInventory;";
                Statement st = conn.createStatement();
            done = st.execute(query);
           
             Statement stt = conn.createStatement();
             String reload = "LOAD DATA local INFILE 'C:/masterin.csv' " +
                         "INTO TABLE masterinventory FIELDS TERMINATED BY ',' " +
                         "OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n';";
             done = stt.execute(reload);
           
              }
              catch (SQLException e)
            {  
               e.printStackTrace();
            }
    }
      /**
       * @param args
       */
      public static void main(String[] args) {
            reloadMaster reload = new reloadMaster();
            reload.executeQueries();
      }
}

***** CODE ENDS HERE ********

I would love it if someone could convert this to C# and point out some of the major differences.
C# seems very interesting : )

Thanks very much!
Wojciech Dunski.
Avatar of mmarksbury
mmarksbury

Better yet, go to http://www.asp.net/vwd/starterkits.aspx?tabIndex=4&tabId=46 and download some of the starter kits.  This is how I learned, and it was amazing at how easy it is to pick up.  I've just made the move from C# to Java due to a work move, and all I can say is you'll be much happier with C#.
ASKER CERTIFIED SOLUTION
Avatar of findsukesh
findsukesh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wdunski

ASKER

Sounds good.
One last question:
Which namespace do I need to use for the OdbcConnection?
I treid System.Data.Obdc but that doesnt seem to work.

Thanks.
Hi Wojciech,

You have to use the namespace System.Data.Odbc. Please check the spelling you have used.

Try and use Visual Studio intellisense to avoid such spelling mistakes.

Regards,
Sukesh.