SVXX

Aakarsha JDBC PrepStatement

Sep 1st, 2013
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package college;
  6. import java.sql.*;
  7.  
  8. public class College {
  9.     public static void main(String[] args) {
  10.         // TODO code application logic here
  11.         Connection con;
  12.         PreparedStatement pstmt;
  13.         try
  14.         {
  15.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  16.             con=DriverManager.getConnection("jdbc:odbc:Aakarshap");
  17.             pstmt=con.prepareStatement("Select eName from Employee where eNum=?");
  18.             pstmt.setString(1, args[0]);
  19.             ResultSet rst=pstmt.executeQuery();
  20.             if(rst != null)
  21.             while(rst.next())
  22.             {
  23.                    System.out.println(rst.getString("eName"));
  24.             }
  25.             else
  26.                 System.out.println("No record found");
  27.            
  28.         }
  29.         catch(ClassNotFoundException ce)
  30.         {
  31.             System.out.println("Error"+ce);
  32.         }
  33.     catch(SQLException se)
  34.     {
  35.         System.out.println("Error"+se);
  36.     }
  37.     }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment