Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5.  
  6. public class DbConnection {
  7.  
  8.  
  9.  
  10. static String url="jdbc:mysql://localhost:3307/dbName";
  11.  
  12. public static Connection con()throws Exception{
  13. Class.forName("com.mysql.jdbc.Driver");
  14. Connection con1=DriverManager.getConnection(url,"root","kaththa");
  15.  
  16. return con1;
  17. }
  18.  
  19. public void putData(String sql) throws Exception{
  20. Statement st=con().createStatement();
  21. st.executeUpdate(sql);
  22. con().close();
  23. }
  24.  
  25. public ResultSet getData(String sql)throws Exception{
  26. Statement st=con().createStatement();
  27. ResultSet rs=st.executeQuery(sql);
  28. con().close();
  29. return rs;
  30. }
  31. public static void main(String args[]) {
  32. try {
  33. DbConnection db=new DbConnection();
  34. System.out.println("sucess");
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment