Advertisement
Guest User

Untitled

a guest
Feb 28th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public Connection dbconnect()
  2. {
  3. Connection conn = null;
  4. String url = "jdbc:mysql://localhost:3306/";
  5. String db = "gup";
  6. String driver = "com.mysql.jdbc.Driver";
  7. String user = "root";
  8. String pass = "";
  9. try{
  10. Class.forName(driver);
  11. conn = DriverManager.getConnection(url + db, user, pass);
  12. if(conn == null){
  13. System.out.println("Connection is not established");
  14. }
  15. return conn ;
  16. }
  17. catch(Exception e)
  18. {
  19. System.out.println(e);
  20. }
  21. return null ;
  22. }
  23.  
  24. public void insertfile(String fpath,String fname,String fext)
  25. {
  26. PreparedStatement pstmt = null;
  27. // Connection conn = null ;
  28. dbConnection dbcon = new dbConnection();
  29. pstmt = (PreparedStatement) dbcon.dbconnect();
  30. //Create the statement object
  31. String sql = "insert into FileDetails (folder_path,file_name,file_extension)" + "values (?,?,?)";
  32. try
  33. {
  34.  
  35. //ResultSet rs = pstmt.executeQuery(sql);
  36. pstmt.setString(1, fpath);
  37. pstmt.setString(2, fname);
  38. pstmt.setString(3, fext);
  39. pstmt.executeQuery(sql);
  40. }
  41. catch(SQLException se)
  42. {
  43. System.out.println(se);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement