Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package jdbc;
  7. import java.io.*;
  8. import java.sql.*;
  9.  
  10. /**
  11. *
  12. * @author MohanDhar
  13. */
  14. public class JDBC {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. Connection conn=null;
  21. try{
  22. Class.forName("com.mysql.jdbc.Driver").newInstance();
  23. String url = "jdbc:mysql://172.16.10.117/cs391";
  24. String dbuser = "cs391";
  25. String dbpass = "abc123";
  26. conn = DriverManager.getConnection(url,dbuser,dbpass);
  27. Statement s = conn.createStatement();
  28.  
  29. s.execute("INSERT INTO TEST(Motto,NNum) VALUES('Rafi Rizwan','12265380');");//throws an exception if it fails
  30.  
  31. }
  32. catch(Exception e){
  33. System.out.println("Connection error: "+e.toString());
  34. }
  35. finally{
  36. try{
  37. conn.close();
  38. System.out.println("Connection Closed!");
  39. }
  40. catch(Exception e){}
  41. }
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement