packages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • menmysql
    New Member
    • Mar 2007
    • 53

    packages

    hi

    i create a package connection and in that i wrote the following program

    package connection;
    import java.sql.Driver Manager;
    import java.sql.Connec tion;
    import java.io.*;
    public class connect
    {
    Connection conn;
    public connect()
    {
    try{
    Class.forName(" com.mysql.jdbc. Driver");
    }
    catch(Exception e)
    {}
    }
    public Connection getConnection()
    {
    try{
    conn=DriverMana ger.getConnecti on("mysql:mysql ://localhost/college","root" ,"");
    }catch(Exceptio n e){}
    return conn;
    }
    }

    ----------------------

    and compiled it. it got compiled then coming out from connection package and once again i created sql package and in that i wrote the following program.


    package sql;

    import connection.*;
    import java.sql.*;

    public class SqlBean
    {
    Connection con=null;

    public SqlBean()
    {
    connect c=new connect();
    con=c.getConnec tion();
    }
    // Insert the records into database
    public int insert(String query)
    {
    int i=0;
    try
    {
    Statement st=con.createSt atement();
    i=st.executeUpd ate(query);
    }
    catch(Exception sql)
    {
    sql.printStackT race();
    }

    return i;
    }
    // it is used to update the records
    public int update(String query)
    {
    int i=0;
    try
    {

    Statement st=con.createSt atement();
    i=st.executeUpd ate(query);
    }
    catch(Exception sql)
    {
    sql.printStackT race();
    }

    return i;
    }
    // it is used to select the records based on Query
    public ResultSet select(String query)
    {
    ResultSet rs=null;
    try
    {
    Statement st=con.createSt atement();
    rs=st.executeQu ery(query);
    return rs;
    }
    catch(Exception sql)
    {
    sql.printStackT race();
    }

    return rs;
    }
    // to close the connection (con)
    public void close()
    {
    try
    {
    if(con!=null)
    {
    con.close();
    }
    }catch(Exceptio n e)
    {
    e.printStackTra ce();
    }
    }
    }

    -------------

    while compilng it is giving the following error "PACKAGE NOT FOUND". can any one what the mistake i did. waiting for reply



    regards
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by menmysql
    hi

    i create a package connection and in that i wrote the following program

    package connection;
    import java.sql.Driver Manager;
    import java.sql.Connec tion;
    import java.io.*;
    public class connect
    {
    Connection conn;
    public connect()
    {
    try{
    Class.forName(" com.mysql.jdbc. Driver");
    }
    catch(Exception e)
    {}
    }
    public Connection getConnection()
    {
    try{
    conn=DriverMana ger.getConnecti on("mysql:mysql ://localhost/college","root" ,"");
    }catch(Exceptio n e){}
    return conn;
    }
    }

    ----------------------

    and compiled it. it got compiled then coming out from connection package and once again i created sql package and in that i wrote the following program.


    package sql;

    import connection.*;
    import java.sql.*;

    public class SqlBean
    {
    Connection con=null;

    public SqlBean()
    {
    connect c=new connect();
    con=c.getConnec tion();
    }
    // Insert the records into database
    public int insert(String query)
    {
    int i=0;
    try
    {
    Statement st=con.createSt atement();
    i=st.executeUpd ate(query);
    }
    catch(Exception sql)
    {
    sql.printStackT race();
    }

    return i;
    }
    // it is used to update the records
    public int update(String query)
    {
    int i=0;
    try
    {

    Statement st=con.createSt atement();
    i=st.executeUpd ate(query);
    }
    catch(Exception sql)
    {
    sql.printStackT race();
    }

    return i;
    }
    // it is used to select the records based on Query
    public ResultSet select(String query)
    {
    ResultSet rs=null;
    try
    {
    Statement st=con.createSt atement();
    rs=st.executeQu ery(query);
    return rs;
    }
    catch(Exception sql)
    {
    sql.printStackT race();
    }

    return rs;
    }
    // to close the connection (con)
    public void close()
    {
    try
    {
    if(con!=null)
    {
    con.close();
    }
    }catch(Exceptio n e)
    {
    e.printStackTra ce();
    }
    }
    }

    -------------

    while compilng it is giving the following error "PACKAGE NOT FOUND". can any one what the mistake i did. waiting for reply



    regards
    Use code tags when posting code.
    Did you create the folders for the packages correclty?

    Comment

    • N002199B
      New Member
      • Feb 2007
      • 41

      #3
      Originally posted by menmysql
      hi

      i create a package connection and in that i wrote the following program

      package connection;
      import java.sql.Driver Manager;
      import java.sql.Connec tion;
      import java.io.*;
      public class connect
      {
      Connection conn;
      public connect()
      {
      try{
      Class.forName(" com.mysql.jdbc. Driver");
      }
      catch(Exception e)
      {}
      }
      public Connection getConnection()
      {
      try{
      conn=DriverMana ger.getConnecti on("mysql:mysql ://localhost/college","root" ,"");
      }catch(Exceptio n e){}
      return conn;
      }
      }

      ----------------------

      and compiled it. it got compiled then coming out from connection package and once again i created sql package and in that i wrote the following program.


      package sql;

      import connection.*;
      import java.sql.*;

      public class SqlBean
      {
      Connection con=null;

      public SqlBean()
      {
      connect c=new connect();
      con=c.getConnec tion();
      }
      // Insert the records into database
      public int insert(String query)
      {
      int i=0;
      try
      {
      Statement st=con.createSt atement();
      i=st.executeUpd ate(query);
      }
      catch(Exception sql)
      {
      sql.printStackT race();
      }

      return i;
      }
      // it is used to update the records
      public int update(String query)
      {
      int i=0;
      try
      {

      Statement st=con.createSt atement();
      i=st.executeUpd ate(query);
      }
      catch(Exception sql)
      {
      sql.printStackT race();
      }

      return i;
      }
      // it is used to select the records based on Query
      public ResultSet select(String query)
      {
      ResultSet rs=null;
      try
      {
      Statement st=con.createSt atement();
      rs=st.executeQu ery(query);
      return rs;
      }
      catch(Exception sql)
      {
      sql.printStackT race();
      }

      return rs;
      }
      // to close the connection (con)
      public void close()
      {
      try
      {
      if(con!=null)
      {
      con.close();
      }
      }catch(Exceptio n e)
      {
      e.printStackTra ce();
      }
      }
      }

      -------------

      while compilng it is giving the following error "PACKAGE NOT FOUND". can any one what the mistake i did. waiting for reply



      regards
      For starters, this code is a bit long to follow. It's no use giving it because the issue that is of concern is the error message and how you are compiling the code.... not the non-compiling code as such. What editor are you using to create your code and how are you compiling it?

      Comment

      • itsraghz
        New Member
        • Mar 2007
        • 124

        #4
        make sure you explicitly put the files in the folders matching with your package hierarchy.

        if you use the command line to compile, ensure you are there in the appropriate parent directory while compiling the files.
        Last edited by itsraghz; Mar 31 '07, 02:28 PM. Reason: its showing the html markups in the submitted reply

        Comment

        Working...