Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String jdbcUrl = "jdbc:sqlserver://localhost\SQLExpress:1433;DatabaseName=Movie;User=username;Password=password;";
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- conn = DriverManager.getConnection(jdbcUrl);
- stmt = conn.createStatement();
- rs = stmt.executeQuery("SELECT TITLE FROM MOVIES;");
- System.out.println(conn);
- if(rs.next()) {
- if(rs.getString(1).contentEquals("TEST")){
- flag = true;
- }else{
- flag = false;
- }
- }
- } catch (SQLException e) {
- System.err.println("Unable to connect to database");
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- System.err.println("Unable to load driver");
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- stmt.close();
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement