Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to export and import from data from syabse database using hibernate

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,
I have a requirement like ,I need to export /import the data from database for that i will get one xml file and one propertie file
1. Table names properties file
2 . Table relation xml

For export i need to export the data to xml file so I have done this part using the following jdbc code but i want to convert this code hibernate and I want to know how to import this data dynamically using hiberante

public class DBTablesExport {
public void export(String filepath) throws SQLException {
Connection con = null;
Statement st = null;

try {
System.out.println("satya");
con = DBConnection.getConnection();

System.out.println("satya ssss");
st = con.createStatement();
PropsUtils props = new PropsUtils();
Properties prop = props.load("dbproperties.properties");
Set set = (Set) prop.keySet();
for (Iterator itr = set.iterator(); itr.hasNext();) {
String paramName = (String) itr.next();
System.out.println("satya paramName" + paramName);
ResultSet rs = st.executeQuery((String) prop
.getProperty(paramName));
ResultSetMetaData md = rs.getMetaData();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory
.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement(paramName);
document.appendChild(rootElement);

int col = md.getColumnCount();

while (rs.next()) {
String element = "row";
Element em = document.createElement(element);
for (int i = 1; i <= col; i++) {
String col_type = md.getColumnTypeName(i);
String col_name = md.getColumnName(i);
Element em1 = document.createElement(col_name);
if (col_type.equals("int")
|| col_type.equals("numeric")
|| col_type.equals("tinyint")) {

Integer iname = rs.getInt(i);
em1.appendChild(document.createTextNode(iname
.toString()));

} else if (col_type.equals("varchar")) {
String colData = rs.getString(i);
em1.appendChild(document.createTextNode(colData));
}
em.appendChild(em1);
}// for
rootElement.appendChild(em);

}// while
FileOutputStream fos = new FileOutputStream("C:/satya33.xml");
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(fos);
transformer.transform(source, result);
}// for

}catch (Exception ex) {
ex.printStackTrace();
}

}
}



so Please help me out do this task
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
nalamati,

Please use code tags.

Do you have the requirement to use JDBC, or Hibernate?
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing this duplicate.
Let's focus on this thread.
    Bookmark Topic Watch Topic
  • New Topic