when i want to insert data into mysql using JdbcOdbc Bridge driver, i get no database selected error,

user5921748

i have created dsn correctly and have clear and simple code but i end up getting this error. the table structure is same as the program

   import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    public class Insert {
        public static void main(String[] args) {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbc");
                Connection con=DriverManager.getConnection("jdbc:odbc:mysqldsn","root","filimon");
                Statement st=con.createStatement();
                int i=st.executeUpdate("insert into emp values(3,'cat')");
                if (i>=1) {
                    System.out.println("inserted successfully");
                } else {
                    System.out.println("failed");
                }
                st.close();
                con.close();
            } catch (Exception e) {
                System.err.println(e);
            }
        }
    }

I get java.sql.SQLException: [MySQL][ODBC 5.3(a) Driver][mysqld-5.7.13-log]No database selected

Abu Sufian

Error said that you haven't selected a database. But selection of the database would be somewhere in the ODBC configuration.

So you can do two things : Either you fix your ODBC configuration to select a database, or (a better option) you can stop using ODBC and use the MySQL JDBC driver.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive