Skip to main content

How to use SQL Exception Methods in java

The following code shows the use of some sqlexception method
package basics.in.java.blogspot.in;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
 
 private static final String USERNAME="root";
 private static final String PASSWORD="";
 private static final String CONN_STRING="jdbc:mysql://localhost/basicsinjavablogspot";
 

 public static void main(String[] args) throws ClassNotFoundException, SQLException {
  Class.forName("com.mysql.jdbc.Driver");
  Connection conn=null;
  Statement stmt=null;
  ResultSet rs=null;
  
  
  try {
   conn= DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
            System.out.println("database connection successful"); 
            stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            rs=stmt.executeQuery("select stateId,stateName from statesz");
            rs.last();
            System.out.println("Number of rows:"+rs.getRow());
  } catch (SQLException e) {
   System.err.println(e);
   System.err.println("Error message:"+e.getMessage());
   System.err.println("Error code is:"+e.getErrorCode());
   System.err.println("sql state:"+e.getSQLState());
   
  }
  
  finally{
   if(rs!=null){
    rs.close();
   }
   if(stmt!=null){
    stmt.close();
   }
   if(conn!=null){
    conn.close();
   }
  }
  

 }

}


Comments

  1. A string describing the error. This is used as the Java Exception message, available via the method getMesasge.
    a "SQLstate" string, which follows either the XOPEN SQLstate conventions or the SQL:2003 conventions. The values of the SQLState string are described in the appropriate spec.

    The DatabaseMetaData method getSQLStateType can be used to discover whether the driver returns the XOPEN type or the SQL:2003 type.

    an integer error code that is specific to each vendor. Normally this will be the actual error code returned by the underlying database.a chain to a next Exception.

    This can be used to provide additional error information.the causal relationship, if any for this SQLException. Java training in chennai | Android training in chennai

    ReplyDelete
  2. Excellant content thanks for sharing the unique information and keep posting.
    Android Training in Chennai | android courses in Chennai | FITA Velachery | FITA Training

    ReplyDelete
  3. Are you a fresher or student searching your first dream job or are you an experienced working professional seeking for an opportunity to change your current working company or job role? Why don't you make the changes your career on java
    JAVA Training in chennai

    ReplyDelete
  4. This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post,thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.. Android Training in Chennai || Android Courses in Chennai || Android Certification in Chennai

    ReplyDelete
  5. Thanks a lot for all your valuable article! We are really happy about the your... ANDROID Training in Chennai

    ReplyDelete
  6. This java basics are good.It is very useful for me.
    SAP ABAP Training in Chennai

    ReplyDelete
  7. The sql exception method is very important one in java. This blog clearly explains the sql exception in java and giving the coded examples. Thanks for this blog. very useful one.
    Informatica Training in Chennai

    ReplyDelete
  8. This blog is informative. It explains about the sql exception in java which helps the freshers to learn easily. the concept was clearly explained.
    Manual Testing Training in Chennai

    ReplyDelete
  9. Its more informative..Clearly explained about How to use exception method in java..Its more informative and useful.Keep on blogging like this..
    Android Training in Chennai

    ReplyDelete
  10. It is very intelligent information.It is clearly explained the SQL exception methods used in java.
    Java j2ee Training in Chennai

    ReplyDelete
  11. very much useful information you are sharing about basics of java and with its architecture explanations.
    keep sharing.
    Loadrunner Training in Chennai

    ReplyDelete
  12. this blog is informative , i am really very happy to know about the information of java which i have already learned , thanks for sharing this information.

    dot net training in chennai

    ReplyDelete
  13. Nice blog..Its more useful blog about How to use SQL Exception Methods in java..Its more informative and useful..Keep on sharing..
    Linux training in chennai

    ReplyDelete
  14. Thank you for this brief explanation and ver nice information. well, got a good knowledge. Have a nice idea, this is more helpful to me. This can gives the better performance.
    Informatica Training in Chennai

    ReplyDelete
  15. This blog provides an detail explanation about the sql exception and its techniques. Thanks for posting this information.
    ssrs training in chennai

    ReplyDelete
  16. valuable information.SQL exception in Java and is useful for me.It is more explained in programming or coding way.


    Sharepoint developer training in chennai

    ReplyDelete

  17. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.


    Java training in Adyar

    ReplyDelete
  18. This article provides the information about Java its key features and scope for java professionals. This information is really helpful me to know more about Java programming language. Java Training in Chennai | Java Training | Java Course in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

Configuring Multiple Profiles in a Single YAML File for Spring Boot Application

Spring Boot provides a convenient way to configure application properties using YAML files. In a typical scenario, you might have different configurations for different environments such as development, testing, and production. Instead of maintaining multiple YAML files for each profile, you can configure multiple profiles within a single YAML file. This approach simplifies the configuration management process. Let's see how to achieve this. Step 1: Create a YAML Configuration File First, create a YAML file (e.g., application.yml ) in your Spring Boot project's resource directory. This file will contain the configuration properties for all the profiles you want to define. spring: profiles: active: dev logging: level: root: INFO com.example: DEBUG # Configuration for the 'dev' profile --- spring: profiles: dev database: url: jdbc:mysql://localhost:3306/devdb username: devuser password: devpassword # Co

A End to End ant Build xml snippet

A End to End ant Build xml snippet you could use for reference <?xml version="1.0" encoding="UTF-8"?> <project name="End to End Build" default="sendmail" basedir=".">     <target name="init">         <tstamp />         <property file="build.properties" />             <path id="classpath">             <pathelement path="${servlet.jar}" />             <pathelement path="${junit.jar}" />         </path>