Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 28th, 2004, 02:51 PM
orozcom orozcom is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 orozcom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
html data extraction and insert to db

I have a jtidy program that produces xhtml or just well formed html. It streams the output as a file. I would like to use regex to find patterns in the html and extract data between these files: Something like

<tag> data </tag>

once I have the data, which almost all of it is text. I would like to use may a preparedStatement to insert the data into an oracle table.

I need example on how to extract the data and insert using preparedStatements or just statements.

Thanks

Reply With Quote
  #2  
Old May 25th, 2004, 01:15 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
I'll give an example about updating. For inserting, you just have to change the SQLstatement. This code is part of a DAO (Data Access Object) which is called by the servlet. The servlet receives the request (through submitting of the form in the JSP), decides where the application should go, and then gives the request to the DAO.


public
Land updateLand(HttpServletRequest _request )
throws SQLException

{

if (_request == null) returnnull ;

else {
HttpSession sessie = _request.getSession(false);
if (sessie == null) returnnull;
else {
Land land = (Land) sessie.getAttribute("land");
if (verschilLandEnFormgegevens(_request) )
{
Connection con = null;
PreparedStatement ps = null;
try {
StringBuffer strUpdate = new StringBuffer();
strUpdate.append("update land ");
strUpdate.append(" set naam=?, landcode=?, opdelingGewenst=?, ");
strUpdate.append(" titelOpdeling=? ");
strUpdate.append(" where ID = ? ");
con = getConnection();
ps = con.prepareStatement(strUpdate.toString());
String formNaam = _request.getParameter("naam");
String formLandcode = _request.getParameter("landcode");
String formOpdeling = _request.getParameter("opdeling");
String formNaamOpdeling = _request.getParameter("naamOpdeling");
boolean opdeling = true;
if (formOpdeling == null) opdeling = false;
ps.setString(1, formNaam);
ps.setString(2, formLandcode);
ps.setBoolean(3, opdeling);
ps.setString(4, formNaamOpdeling);
ps.setInt(5, land.getID());
ps.executeUpdate();
return zoekLandOpID(land.getID());
} catch (SQLException SQLEx)
{
throw SQLEx;
}
finally {
ps.close();
con.close();
}
}
elsereturn land; /* object "land" hasn't changed */
}
/* session != null */



}








}
// end updateLand


Reply With Quote
  #3  
Old May 25th, 2004, 01:17 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
ABout the getConnection() in the previous example : I use a GeneralDao where I define just once how to connect to the database. All the other DAO's are subclasses of this general DAO. And so, it's sufficient to write con = getConnection();
protected Connection getConnection()

throws java.sql.SQLException

{

Connection dbconn =
null;

try

{

Class.forName(
"com.mysql.jdbc.Driver").newInstance();

dbconn = DriverManager.getConnection(
"jdbc:mysql://localhost/brukkerlin");

}
catch (InstantiationException e)

{

System.out.println(
"GeneralDao - Fout bij getConnection - instantiation " );

e.printStackTrace();

}
catch (IllegalAccessException e)

{

System.out.println(
"GeneralDao - Fout bij getConnection - illegal acces " );

e.printStackTrace();

}
catch (ClassNotFoundException e)

{

System.out.println(
"GeneralDao - Fout bij getConnection - class not found " );

e.printStackTrace();

}

return dbconn;

}


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > html data extraction and insert to db


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT