Kód: Vybrať všetko
String url = "jdbc:mysql://localhost:3306/java";
Connection connection=null;
PreparedStatement selectStatement = null;
try {
connection = DriverManager.getConnection(url, "root","root");
selectStatement = connection.prepareStatement("select author from book where id = ?");
selectStatement.setInt(1,1);
ResultSet resultSet = selectStatement.executeQuery();
while(resultSet.next()) {
String author = resultSet.getString("author");
System.out.println("Autor: " + author);
}
} catch (SQLException ex) {
throw new LibraryException(ex.getMessage(), ex.getCause());
} finally {
try {
if(connection != null) {
connection.close();
}
if (selectStatement != null) {
selectStatement.close();
}
} catch (SQLException ex) {
throw new LibraryException("Chyba v uzatvarani.", ex.getCause());
}
}
Kód: Vybrať všetko
No suitable driver found for jdbc:mysql://localhost:3306/java