Hi, Friends to day i am posting my project module in the blog
This is about reading marks information directly from the jntuk results website
This needs the url of the first student result
---------------------------------------------------------------------------------------------------
I am using the mysql database and apache tomcat 6.0 webserver
and i did this in jsp
First you have to create the student rollnumbers data and marks data tables
--->create table studentrollnumber(branch varchar(6),batch int(4),rollnumber varchar(11),primary key(rollnumber));
and enter the required data here
--->create table nettable(snumber int(4),rollnumber varchar(11),mc921int int(3),mc921ext int(3),mc922int int(3),mc922ext int(3),mc923int int(3),mc923ext int(3),mc924int int(3),mc924ext int(3),mc925int int(3),mc925ext int(3),mc926int int(3),mc926ext int(3),mc927int int(3),mc927ext int(3),primary key(rollnumber));
and this table is static . This is the sub module the table will be created automatically by the program in the previous pages
The first page contains the information about branch and batch and url details
and the program of this file is
-->netsave.jsp
--------------------------------------------------------------------------------------------------------------
<html>
<body >
<form name="frm1" action="url8.jsp">
<font style="timesnewroman" size="5">
<center>
<b>
</br></br></br></br></br></br>
Select Branch :
<select name="branch">
<option value="mca">MCA
<option value="mba">MBA
<option value="ece">ECE
<option value="eee">EEE
</select>
Select Batch :
<select name="batch">
<option value="2007">2007
<option value="2008">2008
<option value="2009">2009
<option value="2010">2010
</select>
Past the URL:
<input type="text" value="enter the url of the first student result" size="60" name="url">
</br></br></br></br>
<input type="submit" name="submit" value="submit">
<input type="reset" name="reset" value="cancel">
</b>
</center>
</font>
</form>
</body>
</html>
---------------------------------------------------------------------------------
when you enter the data it will be submited to url8.jsp page
the data will be get from the page as html format
html string is parsed and retrieve the subject code and internal & external marks
the data is saved in the nettable table
the program for getting ,parsing,saving is
url8.jsp
--------------------------------------------------------------------------------
<%@ page language="java" import="java.io.*,java.net.*,java.util.*,java.sql.*;" session="true"
buffer="100kb" %>
<%
try
{
int sno=0;
Connection con= null;
Statement stmt;
String connectionURL = "jdbc:mysql://localhost:3306/nettable";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con= DriverManager.getConnection(connectionURL, "root", "pavan");
stmt=con.createStatement();
String url=request.getParameter("url");
String branch=request.getParameter("branch");
String batch=request.getParameter("batch");
String rollnumber2="08481f0001";
stmt=con.createStatement();
ResultSet result = stmt.executeQuery("select rollnumber from studentrollnumber where branch='"+branch+"' and batch='"+batch+"'");
while(result.next())
{
String rollnumber = result.getString(1);
url=url.replace(rollnumber2,rollnumber);
out.println("RollNumber: "+rollnumber);
out.println("</br>");
out.println("</br>");
URL jntuk = new URL(url);
URLConnection jntukConnection = jntuk.openConnection();
DataInputStream dis = new DataInputStream(jntukConnection.getInputStream());
String inputLine;
String outputLine="";
while ((inputLine = dis.readLine()) != null) {
outputLine=outputLine+inputLine;
}
String nohtml = outputLine.toString().replaceAll("\\<.*?>","");
nohtml=nohtml.toString().replaceAll(" ","");
String delims = "[ ]+";
String[] tokens =nohtml.split(delims);
String[] needed=new String[tokens.length];
int ix=0,iy=0;
for(int i=0;i<tokens.length;i++)
{
tokens[i]=tokens[i].trim();
if(tokens[i].equals("Pass/Fail"))
ix=1;
if(tokens[i].equals("HOME"))
ix=0;
if(ix==1)
{iy++;needed[iy]=tokens[i];}
}
int[] internals=new int[iy];
int[] externals=new int[iy];
String[] subjectcode=new String[iy];
int in=0,ex=0,sc=0;
subjectcode[sc]=needed[3];
for(int iz=1;iz<iy;iz++)
{
if(needed[iz].equals("Pass") || needed[iz].equals("Fail"))
{
internals[in++]=Integer.parseInt(needed[iz-4]);
externals[ex++]=Integer.parseInt(needed[iz-3]);
subjectcode[++sc]=needed[iz+3];
}
}
for (int el=0;el<in;el++)
{
out.println("subject code : "+subjectcode[el]);
out.println(" ");
out.println("internals : "+internals[el]);
out.println(" ");
out.println("externals : "+externals[el]);
out.println("</br>");
}
sno++;
PreparedStatement pst=
con.prepareStatement("insert into nettable values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
pst.setInt(1,sno);
pst.setString(2,rollnumber);
pst.setInt(3,internals[0]);
pst.setInt(4,externals[0]);
pst.setInt(5,internals[1]);
pst.setInt(6,externals[1]);
pst.setInt(7,internals[2]);
pst.setInt(8,externals[2]);
pst.setInt(9,internals[3]);
pst.setInt(10,externals[3]);
pst.setInt(11,internals[4]);
pst.setInt(12,externals[4]);
pst.setInt(13,internals[5]);
pst.setInt(14,externals[5]);
pst.setInt(15,internals[6]);
pst.setInt(16,externals[6]);
pst.addBatch();
int count[]=pst.executeBatch();
if(count.length>0)
out.println("database saved successfully");
else
out.println("error occured");
rollnumber2=rollnumber;
out.println("</br>");
}
}catch (Exception ioe) {
out.println(ioe);
}
%>
--------------------------------------------------------------------------------
so the data will be automatically saved in the data base