Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java with excel using JDBC

 
kalaiselvi Bhalerao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I need to develop a java application to connect with excel using type 4 jdbc driver.
I surfed the net for tutorials but i did not find any.

I have downloaded the Excel_JDBC40.jar file and connected to excel using jdbc connection.


but i am stuck up and have no idea what next has to be done.

It would be greatful if some can help me.

regrads
s.kalaiselvi
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've added code tags to make the code easier to read.

Are you getting an error with that code? If so, what is it? If not, the next step is to add ResultSet code. You loop through the result set and call getters for each column.
 
Wei Dai
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<quote>
I need to develop a java application to connect with excel using type 4 jdbc driver.
I surfed the net for tutorials but i did not find any.
</quote>
It's at HXTT Excel JDBC document

>but i am stuck up and have no idea what next has to be done.
You can find some *.java which is sample to create ResultSet
For instance,
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getString(1));
}
Or
ResultSetMetaData resultSetMetaData = rs.getMetaData();
int iNumCols = resultSetMetaData.getColumnCount();
for (int i = 1; i <= iNumCols; i++) {
System.out.println(resultSetMetaData.getColumnLabel(i)
+ " " +
resultSetMetaData.getColumnTypeName(i));
}

Object colval;
while (rs.next()) {
for (int i = 1; i <= iNumCols; i++) {
colval = rs.getObject(i);
System.out.print(colval + " " + "\t");
}
System.out.println();
}


 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd actually use Apache POI, JExcelAPI or some other library for reading Excel files. To me, Excel files are not database files, and therefore JDBC should not be used to read them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic