Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: calling a constructor

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question calling a constructor

    I have created my class and one constructor in the class and I now want to call my class in the main method.
    How do I call the constructor then. My code looks like this

    import java.sql.*;
       import java.io.*;
       import javax.swing.JOptionPane;
        public class MyConnection
       {
          Connection conn;
           public  MyConnection()
          {
          //load the driver
     
             try
     
             {
                Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
                System.out.println ("Driver successfully loaded");
             }    
                 catch (ClassNotFoundException c)
                {
                   System.out.println ("Unable to load database driver");
                }
          //connect to the database
             try
             {
     
                BufferedReader inKb = new BufferedReader (new InputStreamReader(System.in));
             //String filename = inKb.readLine();
                String filename = "c:/mydatabase.mdb";
                String database = "jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=";
                database += filename.trim () + ";DriverID=22;READONLY=true}";
                conn = DriverManager.getConnection (database, "", "");
                System.out.println ("Connection to Disease database successfully established");
             }
                 catch (Exception e)
                {
                   System.out.println ("Unable to connect to the database");
                }
          } //end connect
       }


  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: calling a constructor

    i think it has something to do with the "This" keyword but im not sure. hopefully a more educated programmer can help.

Similar Threads

  1. Calling for methods
    By soccer_kid_6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 1st, 2010, 12:13 AM
  2. Help Calling Method From Another Class
    By CheekySpoon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 15th, 2010, 10:24 AM
  3. Declaring variables in constructor and compiling
    By Newoor in forum Object Oriented Programming
    Replies: 3
    Last Post: December 5th, 2009, 01:07 PM
  4. Private Constructor
    By Ganezan in forum Object Oriented Programming
    Replies: 4
    Last Post: November 7th, 2009, 04:02 PM
  5. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 04:31 AM