exception
java.lang.NullPointerException
at jdbcstatements.Insertion.main(Insertion.java:37)
Exception in thread "main" java.lang.NullPointerException
at jdbcstatements.Insertion.main(Insertion.java:50)
my code
package jdbcstatements; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import oracle.jdbc.OraclePreparedStatement; public class Insertion { /** * @param args * @throws SQLException * */ public static Connection getConnection()throws Exception{ Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String url="jdbc:oracle:thin:@localhost:1521:orcl"; Connection con=DriverManager.getConnection( url, "scott", "tiger"); System.out.println("connection created"); return con; } public static void main(String[] args) throws SQLException { Connection con=null; OraclePreparedStatement pstmt = null; try { String query = "insert into EMP(ENAME, JOB, SAL) values(?, ?, ?)"; System.out.println("insert the record"); pstmt = (OraclePreparedStatement) con.prepareStatement(query); // create a statement pstmt.setString(1, "Navatha"); // set input parameter 2 pstmt.setString(2, "Manger"); // set input parameter 3 pstmt.setString(3, "3000"); pstmt.executeUpdate(); } catch(Exception e){e.printStackTrace();} finally { pstmt.close(); con.close(); } } }