简体   繁体   中英

unexpected output while using sun.jdbc.odbc.jdbcodbcDriver

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());
        }
    }
}

我认为您需要将sun.jdbc.odbc.jdbcOdbcDriver更改为sun.jdbc.odbc.JdbcOdbcDriver ,即大写“ J”。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM