Advertisement
Guest User

sbd_ lab java

a guest
Oct 25th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package lab_sbd;
  2.  
  3. import java.io.IOException;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Connection;
  7.  
  8. import com.ibm.as400.*;
  9. import com.ibm.as400.access.jdbcClient.*;
  10. import com.ibm.db2.jcc.DB2Driver;
  11.  
  12. public class main {
  13.  
  14. public static void main(String[] args) throws IOException, SQLException {
  15.  
  16.  
  17. String jdbcClassName="com.ibm.db2.jcc.DB2Driver";
  18. String url="jdbc:db2://10.0.2.15:50000/mydb";
  19. String user="db2admin";
  20. String password="db2admin";
  21.  
  22. Connection con = null;
  23. try
  24. {
  25. //Load class into memory
  26. Class.forName(jdbcClassName);
  27. //Establish connection
  28. con = DriverManager.getConnection(url, user, password);
  29.  
  30. }
  31. catch (ClassNotFoundException e)
  32. {
  33. e.printStackTrace();
  34. }
  35. catch (SQLException e)
  36. {
  37. e.printStackTrace();
  38. }
  39. finally
  40. {
  41. if(con!=null)
  42. {
  43. System.out.println("Connected successfully.");
  44. con.close();
  45. }
  46. }
  47. // TODO Auto-generated method stub
  48.  
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement