SQLException Handling ලේසියි


 in SQL
මෙන්න මේ code එකෙන් පුළුවන් SQLException එකක් ආවොත් බලාගන්න



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;




public class Main {


   public static void main(String[] argv) throws Exception {



      Class.forName("com.mysql.jdbc.Driver");

      Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/School_Attendance", "root", "123");



      try {
         connection.createStatement().execute("select wrong");
      } catch (SQLException e) {
         while (e != null) {
         String message = e.getMessage();

         String sqlState = e.getSQLState();

         int errorCode = e.getErrorCode();
         System.out.println("Message : "+message+" State : "+sqlState+"Errorcode : "+errorcode );
      }


   }



 }


}

0 comments:

Post a Comment