Guest User

Adriana

a guest
Jan 13th, 2016
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 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 db;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13. *
  14. * @author Corina
  15. */
  16. public class DBUtils {
  17. public static PreparedStatement getPreparedStatement(String sql) throws ClassNotFoundException, SQLException{
  18. PreparedStatement ps = null;
  19. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  20. String url= "jdbc:sqlserver://localhost:1433:databaseName=";
  21. String user= "sa";
  22. String pass="123456789";
  23.  
  24. Connection con = DriverManager.getConnection(url, user, pass);
  25. ps = con.prepareStatement(sql);
  26.  
  27. return ps;
  28. }
  29.  
  30. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  31. getPreparedStatement("select * form News");
  32. }
  33. }
Add Comment
Please, Sign In to add comment