0

I want to insert a row into an Excel sheet using Java but instead of getting expected output, I get an output as sun.jdbc.odbc.JdbcOdbc.Driver. I am using JDK 1.6.0

import java.sql.*;
import java.util.*;

class ins
{
    public static void main(String args[])
    {
        try

        {
            Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:DSNxls");

            Statement st=con.createStatement();

            Scanner sc=new Scanner(System.in);
            System.out.println("Please enter your firstname.");
            String fnamej=sc.next();

            System.out.println("Please enter your middlename.");
            String mnamej=sc.next();


            System.out.println("Please enter your lastname.");
            String lnamej=sc.next();


            st.executeUpdate("insert into [Sheet1$]    values("+fnamej+","+mnamej+","+lnamej+")");
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
Andreas
  • 4,832
  • 6
  • 40
  • 49
  • 1
    change `System.out.println(e.getMessage())` to `e.printStackTrace()` and post the stack trace in your question so we can se what is going on. – DaveH Feb 14 '17 at 10:16
  • i forgot to share that i create a system dsn called DSNxls by going to Control panel->administrative tools->Data Sources(ODBC) – Ishuta Wankhede Feb 14 '17 at 10:17
  • java.lang.ClassNotFoundException: sun.jdbc.odbc.jdbcOdbcDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) – Ishuta Wankhede Feb 14 '17 at 10:19
  • this is wat i get after i made changes – Ishuta Wankhede Feb 14 '17 at 10:19
  • i read this page on stackoverflow – Ishuta Wankhede Feb 14 '17 at 10:21
  • http://stackoverflow.com/questions/22984438/java-lang-classnotfoundexception-sun-jdbc-odbc-jdbcodbcdriver-exception-occurin – Ishuta Wankhede Feb 14 '17 at 10:21
  • take a look at this answer: http://stackoverflow.com/questions/19709843/jdbc-odbc-driver-connection – Karim Feb 14 '17 at 10:21
  • but is there any other way of fixing this? – Ishuta Wankhede Feb 14 '17 at 10:21
  • @IshutaWankhede are you using java 8? this may be helpful http://stackoverflow.com/questions/21955256/manipulating-an-access-database-from-java-without-odbc – Shubham Chaurasia Feb 14 '17 at 10:23

2 Answers2

0

I think you need to change sun.jdbc.odbc.jdbcOdbcDriver to sun.jdbc.odbc.JdbcOdbcDriver, i.e. capitalize 'J'.

Shubham Chaurasia
  • 2,096
  • 2
  • 12
  • 20
-1

You need to use Java 8 to solve this problem or download some jar files and make a few code changes. Here is the link of a video which will help you completely:

https://youtu.be/DhuafZrlWq4

Anand Kothari
  • 49
  • 1
  • 2
  • No, the problem was an incorrect class name. See the answer given in 2017, where the OP explains that it was fixed. – Jon Skeet Mar 16 '19 at 21:35