Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Erstellt von: philipp
- * Erstellt am: 21.07.2010 um 20:59:37
- * Projekt: mylab/mysql
- *
- */
- package mysql;
- import java.sql.*;
- public class FirstTest {
- static Connection con = null;
- static Statement stmt = null;
- static ResultSet rs = null;
- public static void main (String[] args) throws InstantiationException, IllegalAccessException, SQLException{
- try{
- System.out.println("Create new driver instance ...");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- System.out.println("Created new driver instance!");
- System.out.println("Created new connection instance!");
- con = DriverManager.getConnection("jdbc:mysql://localhost/javatest", "mysql", "mysql");
- }
- catch(ClassNotFoundException e){
- e.getMessage();
- System.exit(1);
- }
- try{
- stmt = con.createStatement();
- // Daten aus Tabelle bekommemn
- rs = stmt.executeQuery("SELECT nr,name,sontiges FROM TEST_TABELLE");
- while (rs.next()){
- System.out.println("Nr: " + rs.getString(1));
- System.out.println("Name: " + rs.getString(2));
- System.out.println("Sonstiges: " + rs.getString(3));
- System.out.println("bla: " + rs.getString(1));
- }
- // Update der Daten
- stmt.executeUpdate("INSERT INTO TEST_TABELLE (nr, name, sontiges) VALUES ('1', 'phil', 'if')");
- stmt.close();
- con.close();
- }
- catch(SQLException e){
- e.getMessage();
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement