I get this error in my Java programme which coded by me according to a tutorial.I coded it to connect my Java App with MySql database.This is the code.

package Gui;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
/**
 *
 * 
 */
public class connectionconfig
{
private connectionconfig()
    {
        Connection con=null;
        try{
           Class.forName("com.mysql.jdbc.Driver");
           con=DriverManager.getConnection("jdbc:mysql://localhost:3307/musicdb","","pro");
           
         }catch(SQLException ex){
          ex.printStackTrace();
         }catch(ClassNotFoundException ex){
             ex.printStackTrace();
         }
    }


public static void main(String args[])throws Exception{
    Connection connection=getConnection();
    Statement st=null;
    ResultSet rs=null;
    try{
    st=connection.createStatement("");
    rs=st.executeQuery("select count(*) from musicdata");
    rs.next();
    int musicCount=rs.getInt(1);
    System.out.println("Music Count:"+musicCount);
    }finally{
      if(st!=null){
         st.close();
        }
      if(rs!=null)
      {
        rs.close();
      }
      if(connection!=null)
               {
                   try
                   {
                       connection.close ();
                       System.out.println ("Database connection terminated");
                   }
                   catch (Exception ex) { /* ignore close errors */ }
               }
      }
    }
}

i get error in "Connection connection=getConnection();" and "st=connection.createStatement("");" statements

Plz help me......

Edited 5 Years Ago by pro_learner: n/a

What "error"? Post the complete stacktrace. "It doesn't work" (which is essentially what you have said) is the singularly most useless problem description in the world.

In netbeans when i press ALT+ENTER(to get the error),it says can't find symbol.

This article has been dead for over six months. Start a new discussion instead.