1. import java.sql.*;
  2.  
  3. import java.text.ParseException;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. public class DBVerbindung
  13. {
  14.  
  15. /**
  16.   * @param args the command line arguments
  17.   */
  18. public static void verbindung() throws ParseException
  19. {
  20. try
  21. {
  22. String db_file_name_prefix = "C:\\Users\\Andreas\\workspace\\TinaProjekt\\src\\Name.sql";
  23.  
  24. Connection con = null;
  25. // Load the HSQL Database Engine JDBC driver
  26. // hsqldb.jar should be in the class path or made part of the current jar
  27. Class.forName("com.mysql.jdbc.Driver");
  28.  
  29. // connect to the database. This will load the db files and start the
  30. // database if it is not alread running.
  31. // db_file_name_prefix is used to open or create files that hold the state
  32. // of the db.
  33. // It can contain directory names relative to the
  34. // current working directory
  35. con = DriverManager.getConnection("jdbc:mysql:file:" + db_file_name_prefix, // filenames
  36. "sa", // username
  37. ""); // password
  38.  
  39. Statement statement = con.createStatement();
  40. //look at " for table name
  41. ResultSet rs = statement.executeQuery("SELECT * FROM Name");
  42.  
  43. //print the result set
  44. while (rs.next())
  45. {
  46. System.out.print("Schirm: " + rs.getString("Name"));
  47. }
  48.  
  49. statement.close();
  50. con.close();
  51.  
  52. } catch (SQLException ex)
  53. {
  54. Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  55. ex.printStackTrace();
  56. } catch (ClassNotFoundException ex)
  57. {
  58. Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  59. }
  60.  
  61. }
  62.  
  63. public void schliesseVerbindung()
  64. {
  65. Connection con = null;
  66. Statement stmt = null;
  67. try
  68. {
  69. stmt.close();
  70. con.close();
  71. }
  72. catch (SQLException sqle)
  73. {
  74. System.out.println(sqle.toString());
  75. }
  76. }
  77. }
  78.  
  79.