Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: jdbc

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jdbc

    how to connect excel in jdbc

  2. #2

  3. #3

    Default Re: jdbc

    1. Create a new ODBC Data Source using the Microsoft Excel Driver. Name the DSN "excel", and have it point to c:users.xls.

    2. Type in the following code:

    package classes;
    import java.sql.*;

    public class TestServer
    {
    static
    {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch (Exception e) {
    System.err.println(e);
    }
    }

    public static void main(String args[]) {
    Connection conn=null;
    Statement stmt=null;
    String sql="";
    ResultSet rs=null;

    try {
    conn=DriverManager.getConnection("jdbcdbc:excel","","");
    stmt=conn.createStatement();
    sql="select * from [Sheet1$]";
    rs=stmt.executeQuery(sql);

    while(rs.next()){
    System.out.println(rs.getString("USERID")+
    " "+ rs.getString("FIRST_NAME")+" "+
    rs.getString("LAST_NAME"));
    }
    }
    catch (Exception e){
    System.err.println(e);
    }
    finally {
    try{
    rs.close();
    stmt.close();
    conn.close();
    rs=null;
    stmt=null;
    conn=null;
    }
    catch(Exception e){}
    }
    }
    }
    Notice that we have connected to the Excel ODBC Data Source the same way we would connect to any normal database server.

Similar Threads

  1. jdbc
    By vaibz20v in forum JDBC & Databases
    Replies: 1
    Last Post: April 13th, 2013, 11:29 AM
  2. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  3. jdbc
    By kundalikk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 2nd, 2011, 04:38 AM
  4. JDBC
    By Abdul Rasheed in forum JDBC & Databases
    Replies: 1
    Last Post: August 13th, 2010, 07:01 AM
  5. Help with JDBC
    By michaelmel in forum JDBC & Databases
    Replies: 0
    Last Post: May 14th, 2010, 07:11 AM