package paketMySQLDBSichern;
import java.sql.*;

public class DBVerbindung
{

private	Statement stmtSQL = null;  // Objekt für die Ausführung von 	SQL-Anweisungen

 private java.sql.Connection dieVerbindung;

 public boolean oeffneDB()  
 {
	 boolean ok=true;

	 try
  {

   // mit nativem Treiber
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   dieVerbindung = DriverManager.getConnection("jdbc:mysql://127.0.0.1/mysql","root","");
   stmtSQL = dieVerbindung.createStatement();
  }
  catch (Exception ex)
  {
	  ok = false;
	  System.out.println("DB-Fehler: " + ex);
   }
	 return ok;
 }
 
 public boolean aendern(String pSQL)
 { 
	 boolean ok = true;
		try 
		{
			stmtSQL.executeUpdate(pSQL); 
		
		}
		catch (SQLException err) 
		{
			ok = false;
			
		}
		return ok;
	}


	public  boolean schliesseDB()
	  {
		boolean ok = true;
		  try
		  {
			  stmtSQL.close();
			  dieVerbindung.close();
		  }
		  catch (Exception err)   
		  {
			  ok = false;
		  }
		  return ok;
	  }
	public  ResultSet lesen(String pSQL)                 
		{
		  ResultSet rs;                            

		  try
		  {
			rs = stmtSQL.executeQuery(pSQL);
			 
	 	  }
		  catch(SQLException err)
		  {
			rs = null;
		  }
		  return rs;
		}
}



