00001 package edu.tum.cs.util.db; 00002 00003 import java.sql.Connection; 00004 import java.sql.DriverManager; 00005 import java.sql.ResultSet; 00006 import java.sql.SQLException; 00007 import java.sql.Statement; 00008 00009 public class MySQLConnection { 00010 protected Connection conn; 00011 00012 public MySQLConnection(String host, String user, String password, String database) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { 00013 Class.forName("com.mysql.jdbc.Driver").newInstance(); 00014 String port = "3306"; 00015 String connectString = "jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + user + "&password=" + password; 00016 conn = DriverManager.getConnection(connectString); 00017 } 00018 00019 public void execute(String query) throws SQLException { 00020 Statement statement = conn.createStatement(); 00021 statement.execute(query); 00022 } 00023 00024 public ResultSet select(String query) throws SQLException { 00025 Statement statement = conn.createStatement(); 00026 ResultSet rs = statement.executeQuery(query); 00027 return rs; 00028 } 00029 }