Lunarpages Web Hosting Forum

Author Topic: Java - sql connectivity  (Read 1030 times)

Offline sunena

  • Newbie
  • *
  • Posts: 1
Java - sql connectivity
« on: April 08, 2004, 02:07:29 AM »
i am not able to connect my java /jsp code with mysql databse please send the coding of java-sql connectivity
SUNENA

Offline fignamoya

  • Trekkie
  • **
  • Posts: 19
Java - sql connectivity
« Reply #1 on: August 12, 2004, 01:08:09 PM »
Connection con = null;
Statement st = null;
ResultSet rs = null;

Class.forName("com.mysql.jdbc.Driver").newInstance();
            con = DriverManager.getConnection("jdbc:mysql://host/database","username", "password");
         st = con.createStatement();
here is what you can do with this:
rs = st.executeQuery("some sqlstatement");
make sure you have some kind of close method in the end like such
public boolean close()
   {
      try
      {
           if(rs != null)
             rs.close();
           if(st != null)
             st.close();
           if(con != null)
             con.close();
           return true;
         }
         catch (SQLException e)
         {
            return false;
         }

   }