user544079
user544079

Reputation: 16639

jdbc - sql server not showing any output / error in the console

I am trying to connect to sql server 2005 from my Java application using

try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String connectionurl = "jdbc:sqlserver://servername\\SQLEXPRESS;" + "database=master";
        Connection con = DriverManager.getConnection(connectionurl);
        System.out.println("Connected to SQL Server");
        String sql = "select * from employee";
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        while(rs.next()){
            System.out.println(rs.getString(1) + " " + rs.getString(2));
        }
    }
    catch(Exception e){
        System.out.println(e.getMessage());
    }
}

On executing it, I do not get any output / error at the console. What am I missing?

Upvotes: 1

Views: 1557

Answers (2)

venu
venu

Reputation: 21

actually,the correct answer is...

when you insert the record in sql prompt we have to commit that record by command commit; sql>commit;

even thought when you insert the record after that you can check by command select *from table;

record is inserted successfully...record is there

but in command prompt when we executing java program records are not displaying....

so commit the record when u inserted..

thankyou

Upvotes: 0

BlackJoker
BlackJoker

Reputation: 3191

Maybe there is no records in the table employee. Or it throws an Exception whose e.getMessage() returns ""(I don't think so,but to avoid it,You can use e.printStackTrace() instead).

Upvotes: 1

Related Questions