Before you killing me, I know about the:
http://www.daniweb.com/forums/thread141776.html , but for the moment, I DON"T have the time.
Secondly, I'm new to Java platform and JSP.
I'm trying to make a simple application, but I don't get it.
I'm using Intellij 8, Tomcat 6, MySQL
I have a java class which makes the connection with the database and a jsp file, but is not working.
The java file:
package com.packages;
import java.sql.*;
public class conexiune
{
String URL = "jdbc:mysql://localhost:3306/agenda";
String user = "root";
String pass = "root";
Connection con;
Statement stat;
PreparedStatement pre;
ResultSet res;
public void creeaza()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(URL, user, pass);
}
catch(Exception ex)
{
}
}
public void inchide()
{
try
{
con.close();
}
catch(Exception ex)
{
}
}
public ResultSet interogheaza(String sql)
{
try
{
stat = con.createStatement();
res = stat.executeQuery(sql);
return res;
}
catch(Exception ex)
{
return null;
}
}
public ResultSet interogheazaPrepared(String Sql, String Sql2)
{
try
{
pre = con.prepareStatement(Sql);
pre.setString(1, Sql2);
res = pre.executeQuery ();
return res;
}
catch(Exception ex)
{
return null;
}
}
}
The JSP file:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="conex" scope="page" class="com.packages.conexiune" />
<html>
<head>
<title>
Lista contactelor
</title>
<SCRIPT LANGUAGE="JavaScript">
</SCRIPT>
</head>
<body>
<form name="form" action="index.jsp" method="get">
Cautare
<input name="cauta" type="text">
<input type="submit" name="nume" value="Nume">
<input type="submit" name="oras" value="Oras">
</form>
<form name="form" action="afisare.jsp" method="get">
<table border="0" cellspacing=0 width="100%">
<tr>
<th>Lista contactelor</th>
</tr>
</table>
<br/>
<table border="1" cellspacing=0 width="100%">
<tr>
<th>Nr. crt.</th>
<th>Nume</th>
<th>Prenume</th>
<th>Adresa</th>
<th>Zip</th>
<th>Oras</th>
<th>Telefon</th>
<th>Civila</th>
<th>Nr. copii</th>
<th>Adresa mail</th>
</tr>
<%
conex.creeaza();
int i = 1;
ResultSet res;
res = conex.interogheaza("SELECT * from adresa");
while (res.next())
{
%>
<tr>
<td align="center"> <input type="radio" name="punct" checked="checked" value="<%=res.getString("id") %>"><%=i %></td>
<td align="center"><%=res.getString("Nume") %></td>
<td align="center"><%=res.getString("Prenume")%></td>
<td align="center"><%=res.getString("Adresa")%></td>
<td align="center"><%=res.getString("Cod_Zip")%></td>
<td align="center"><%=res.getString("Oras")%></td>
<td align="center"><%=res.getString("Nr_telefon")%></td>
<td align="center"><%=res.getString("Stare_civila")%></td>
<td align="center"><%=res.getString("Nr_copii")%></td>
<td align="center"><%=res.getString("Adresa_Mail")%></td>
<%
i++;
}
%>
</tr>
</table>
<br/>
<input type="submit" name="adaug" value="Adauga">
<input type="submit" name="modific" value="Modifica" >
<input type="submit" name="sterg" value="Sterge" onclick="return confirm('Doriti stergerea persoanei selectate?');" />
</form> </body>
</html>
When I'm trying to run the app, I receive this error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 65
62: int i = 1;
63: ResultSet res;
64: res = conex.interogheaza("SELECT * from adresa");
65: while (res.next())
66: {
67: %>
68: <tr>