Here is my code CoreDataDetails.java code:
package Helper;
import java.sql.* ;
import java.io.*;
public class CoreDataDetails
{
public CoreDataDetails()
{
try
{
// ensure the JDBC driver class is loaded
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe)
{ cnfe.printStackTrace();
}
}
public String execute(String st, int e, Writer out)
{
String ret = "unknown";
try
{
String sql = "SELECT * FROM Projects WHERE Status = '" +st+"' and EntryType='"+e+"' ";
Connection con = DriverManager.getConnection("jdbc
dbc:AcessCore");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(sql);
while (rs.next())
{
String projectNum = rs.getString(1);
String subject = rs.getString(2);
String title = rs.getString(10);
out.write("<th>");
out.write("<a td href='ProjectDetails.jsp?id=" + projectNum + "'>"+projectNum+"</td>");
out.write("<td>"+subject+"</td>");
out.write("<td>"+title+"</td>");
System.out.println(title);
out.write( "</TR>" );
ret = projectNum;
}
rs.close();
s.close();
con.close();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
catch(IOException eio)
{
}
return ret;
}
public String execute1(int st, int e, Writer out)
{
String et = "unknown";
try
{
String sql = "SELECT * FROM Projects WHERE ProjectSubject = '" +st+"' and EntryType='"+e+"' ";
Connection con = DriverManager.getConnection("jdbc
dbc:AcessCore");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(sql);
while (rs.next())
{
String projectNum = rs.getString(1);
String subject = rs.getString(2);
String title = rs.getString(10);
out.write("<th>");
out.write("<a td href='ProjectDetails.jsp?id=" + projectNum + "'>"+projectNum+"</td>");
out.write("<td>"+title+"</td>");
System.out.println(title);
out.write( "</TR>" );
et = projectNum;
}
rs.close();
s.close();
con.close();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
catch(IOException eio)
{
}
return et;
}
public String execute2(int st, Writer out)
{
String et = "unknown";
try
{
String sql = "SELECT * FROM NepruPublications WHERE PublicationTypeID = '" +st+"'";
Connection con = DriverManager.getConnection("jdbc
dbc:AcessCore");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(sql);
while (rs.next())
{
//read data from database
String publicationNum=rs.getString(1);
String subject=rs.getString(2);
String authors=rs.getString(3);
String YearPublished=rs.getString(5);
out.write("<TR>");
out.write("<th>");
out.write("<a tdhref='ProjectDetails.jsp'>"+publicationNum+"</td>");
out.write("<td>"+subject+"</td>");
out.write("<td>"+authors+"</td>");
out.write("<td>"+YearPublished+"</td>");
out.write( "</TR>" );
et = publicationNum;
}
rs.close();
s.close();
con.close();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
catch(IOException eio)
{
}
return et;
}
}
Only one line changed on my jsp page for examplw:
</tr><% String publicationNum = CoreDataDetails.execute2(1,out);
Sorry for insisting for much :roll: