Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class InventarDB {
- public static void main(String[] args) {
- Connection con = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Treiber loaded .... yey");
- }
- catch(ClassNotFoundException cnfe) {
- System.out.println("Treiberklasse nicht gefunden!");
- System.exit(1);
- }
- try {
- con = DriverManager.getConnection("jdbc:mysql://localhost/inventar", "matthias", "test123");
- System.out.println("Verbindung hergestellt.");
- }
- catch(SQLException se) {
- System.out.println("Verbindung konnte nicht hergestellt werden.");
- }
- Statement stmt = null;
- try {
- stmt = con.createStatement();
- System.out.println("Statement ok");
- }
- catch(SQLException se)
- {
- System.out.println("Abfrage nicht möglich");
- }
- String abfrage = "select * from personal";
- ResultSet rs = null;
- try {
- rs = stmt.executeQuery(abfrage);
- System.out.println("Execute OK");
- }
- catch(SQLException se)
- {
- System.out.println("Abfrage nicht erfolgt");
- }
- rs.next();
- System.out.println("1. Zeile." + rs.getInt(1) + " " + rs.getString(2) + rs.getString(3));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement