Я пытаюсь подключить SQL Server 2008 с сервлетом. Это мой код.
public class ProcessServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ProcessServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// Declare the JDBC objects.
Connection con = null;
ResultSet rs = null;
try {
// Establish the connection.
SQLServerDataSource ds = new SQLServerDataSource();
ds.setUser("sa");
ds.setPassword("password123");
ds.setServerName("ENMEDIA-EA6278E\\ENMEDIA");
ds.setDatabaseName("DishTV_Voting");
con = ds.getConnection();
// Execute a stored procedure that returns some data.
Statement stmt = con.createStatement();
/* stmt.executeUpdate("CREATE DATABASE hello");
stmt.executeUpdate("Use hello");
String table =
"CREATE TABLE Employee11(Emp_code integer, Emp_name varchar(10))";
stmt.executeUpdate(table);
System.out.println("Table creation process successfully!");*/
rs = stmt.executeQuery("SELECT question_text FROM
otvtbl_question WHERE question_id = 10");
while ( rs.next() ) {
String lastName = rs.getString("question_text");
System.out.println(lastName);
}
con.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request,response);
}
}
Я получаю следующую ошибку
Jul 15, 2011 6:56:04 PM com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
SEVERE: Java Runtime Environment (JRE) version 1.6 is not supported by this driver.
Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
Got an exception!
Java Runtime Environment (JRE) version 1.6 is not supported by this driver.
Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.