import java.sql.*;
/*
* SQLException
*/
public class SQLExceptionDemo {
public static void main(String[] args) {
Connection conn = null;
try {
String connUrl = "jdbc:sqlserver://localhost:1433;databaseName=jdbc";
conn = DriverManager.getConnection(connUrl, "sa", "passw0rd");
String qryStmt = "SELECT * FROM employe"; // error here
PreparedStatement stmt = conn.prepareStatement(qryStmt);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println("name = " + rs.getString("ename"));
System.out.printf("salary =" + rs.getDouble("salary"));
}
} catch (SQLException e) {
System.out.println("Message : " + e.getMessage());
System.out.println("Vendor code : " + e.getErrorCode());
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}// end of main()
}// end of class SQLExceptionDemo
文章標籤
全站熱搜
