Guest User

Connecting SQL

a guest
Apr 18th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. https://dev.mysql.com/downloads/connector/j/5.1.html (download it)
  3.  
  4. platform independant
  5.  
  6. open eclipse
  7.  
  8. make project
  9.  
  10. right click project
  11.  
  12. go to properties
  13.  
  14. java build path
  15.  
  16. libraries
  17.  
  18. add external jars
  19.  
  20.  
  21.  
  22. import java.sql.*;
  23.  
  24. class myexample{
  25. private connection con;
  26. private statements st; (for queries)
  27. private resultset rs; (to store result of queries)
  28. private preparedstatements prep;
  29.  
  30. myexample (){
  31. con=nulll;
  32. st=null;
  33. rs=null;
  34. prep=null;
  35.  
  36. }
  37.  
  38. public void run(){
  39. class.ForName(com.Mysql.jdbc.Driver");
  40.  
  41. con = driverMnaager.getConnection("jdbc:mysql://localhost/Faadi?user="Root"") (Root ki jagan user name aaey ga, Faadi ki jagan db name m)
  42.  
  43. st = con.createStatement();
  44.  
  45. query = "create table sc(id int not null, name varchar(40), primary key(id))";
  46.  
  47. st.executeUpdate(query);
  48.  
  49. query = ""
  50.  
  51.  
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment