Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package dbtest;
- import java.sql.*;
- /**
- *
- * @author User
- */
- public class DbTest {
- public static void main(String[] args) throws SQLException
- {
- Connection myConn = null;
- Statement myStmt = null;
- ResultSet myRs = null;
- String uname = "root";
- String pass = "hej";
- try
- {
- myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/library?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", uname, pass);
- myStmt = myConn.createStatement();
- myRs = myStmt.executeQuery("select * FROM skadespelare");
- while (myRs.next())
- {
- System.out.println(myRs.getString("fNamn") + ", " + myRs.getString("eNamn"));
- }
- }catch(Exception exc)
- {
- exc.printStackTrace();
- }finally
- {
- if(myRs != null)
- {
- myRs.close();
- }
- if(myStmt != null)
- {
- myStmt.close();
- }
- if(myConn != null)
- {
- myConn.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement