简体   繁体   中英

JDBC connectivity issue

My code for connection with access database is this...its working fine here... i have tried to connect my database with java derby embedded database but always getting sql exception assuming the same table what changes do i need to connect my application with java derby embedded database??

 package database;
    import java.sql.*;
    import javax.swing.JOptionPane;

       public class database {

        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {

            try
            {
                String url = "jdbc:odbc:personnew";
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection(url);
            Statement st=con.createStatement();
            String sql="SELECT * FROM Person";
            ResultSet rs=st.executeQuery(sql);
            while(rs.next()){
            String id=rs.getString("id");
            String name=rs.getString("name");
            String fathername=rs.getString("fathername");
            JOptionPane.showMessageDialog(null,id+"\t"+name+"\t"+fathername);
            }
            // TODO code application logic here
        }catch(Exception sqlEx){
            System.out.println("Sql exception");
        }
    }
    }

For one thing, You would need to use the correct JDBC driver; org.apache.derby.jdbc.EmbeddedDriver

http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html

The tutorial in general is probably where you want to start as it tells you everything you need to know:

http://db.apache.org/derby/papers/DerbyTut/index.html

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