Category: ASP
To connect to a database from a JSP page on a premier plan, please paste the following into a JSP page, upload and run using a browser, make sure to replace the values which are surrounded by square brackets in the code below
<%@ page import="java.sql.*" %> <% String connectionURL = "jdbc:mysql://localhost:3306/[databasename"; Connection connection = null; Statement statement = null; ResultSet rs = null; %> <% Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection(connectionURL, "[username", "[password"); statement = connection.createStatement(); rs = statement.executeQuery("SELECT [field FROM table"); while (rs.next()) { out.println(rs.getString("[field")+" "); } rs.close(); %>
JSP