Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.servlet.ServletException;
- import com.mysql.jdbc.Connection;
- public class SqlConnection {
- final static String driverName = "com.mysql.jdbc.Driver";
- String url="jdbc:mysql://localhost/ksiegarnia";
- String uid="root";
- String pwd="********";
- private static Connection con=null;
- public Connection getConnection() throws ServletException{
- if(con==null){
- try{
- Class.forName(driverName);
- con=(Connection) DriverManager.getConnection(url,uid,pwd);
- System.out.println("Połączenie z bazą udane");
- }
- catch(Exception e){
- throw new ServletException("Brak połączenia z bazą",e);
- }
- }
- return con;
- }
- public void close() throws SQLException {
- // TODO Auto-generated method stub
- con.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement