简体   繁体   English

JDBC连接问题

[英]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?? 我与访问数据库的连接代码是...在这里工作正常...我试图将数据库与Java derby嵌入式数据库连接,但总是在假设同一个表的情况下出现sql异常,我需要用什么更改来连接我的应用程序java derby嵌入式数据库?

 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; 一方面,您将需要使用正确的JDBC驱动程序。 org.apache.derby.jdbc.EmbeddedDriver

http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html 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 http://db.apache.org/derby/papers/DerbyTut/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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