FAQ
   manual.pipni.cz > Databáze  |  Vyhledávání  |  Problémy?

Jak se připojit k MySQL z JSP?
Velice jednoduchá ukázka jak to provést:
<%@ page contentType = "text/html;charset=windows-1250" %>
<%@ page import="java.sql.*, java.text.NumberFormat" %>

<%
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  Connection connection = DriverManager.getConnection("jdbc:mysql://mysql/database?user=user&password=pwd");
  Statement statement = connection.createStatement();
  ResultSet resultset;
  resultset = statement.executeQuery("SELECT * FROM table");
  while (resultset.next())
  {
    out.print(resultset.getString("id"));
    out.println("<br />");
  }
  resultset.close();
  statement.close();
  connection.close();
%>

Celkový počet rad: 141
Created by PIPNI
Powered by Firebird