package beans;
import java.io.*;
import java.sql.*;

public class ConnectionBean implements java.io.Serializable {
	private static final String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	private static final String url = "jdbc:microsoft:sqlserver://srvninho01:1433;DatabaseName=Opentour";
	private Statement stmt;
	private Connection con;
	private String error;

		public ConnectionBean() {
			try {
				Class.forName(driver);
				con = DriverManager.getConnection(url, "Open", "ninho");
				stmt = con.createStatement();
			}
			catch (SQLException e) {
				error = "SQL error:" + e.getMessage();
				con = null;
			}
			catch (ClassNotFoundException e) {
				error = "Driver error:" + e.getMessage();							
				con = null;
			}
		}

		public Connection getConnection() {
			return con;
		}

		public Statement getStatement() {
			return stmt;
		}

		public String getError() {
			return error;
		}

		public ResultSet executeQuery(String sql) throws SQLException {
			return stmt.executeQuery(sql);
		}

		public int executeUpdate(String sql) throws SQLException {
			return stmt.executeUpdate(sql);
		}

		protected void finalize() {
			try	{
				con.close();
			}
			catch (SQLException e) {
			}
		}

}