Home > Database > Mysql Tutorial > 如何连接myeclipse和access

如何连接myeclipse和access

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:36:48
Original
1426 people have browsed it

如何连接 myeclipse 和 access ,其实 myeclipse 中的项目中的 library 里有 rt.jar ,但是我也不知道为什么最后还是要在 myeclipse 中的 lib 里添加了一个 rt.jar 。这一点还是很令我困惑的。 现在说说是怎么连接 myeclipse 和 access 的,首先点击: 控制

如何连接myeclipseaccess,其实myeclipse中的项目中的library里有rt.jar,但是我也不知道为什么最后还是要在myeclipse中的lib里添加了一个rt.jar。这一点还是很令我困惑的。

现在说说是怎么连接myeclipseaccess的,首先点击:

控制面板->系统安全->管理工具->数据源(ODBC)

在系统打开数据源后,DNS中添加microsoft access driver数据源名随便你取。

点击“选择”,选择你创建的access数据库,比如我的是“Student.mdb”,随后点击确认即可。

其次,要把rt.jar添加到myeclipselib里,因为rt.jar里有sun.jdbc.odbc.driver。如果你的电脑里有jdk,那么在jdklib里找一下有没有rt.jar,如果没有jdk的话,去网上下一个jdbc:odbc的驱动包,让后放到myeclipselib里。

添加了以后在环境变量里添加classpath,路径为驱动包的绝对路径,例如c:myeclipse/lib/驱动包名.jar,添加完后,需要重启你的电脑,然后就可以连接了。

一下是我的几个程序:

package JDBC;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

 

publicclass Insert1 {

    publicstaticvoid main(String[] args) throws Exception{

   String url="jdbc:odbc:DDSchool";

 //url表示需要连接的数据源的位置,此时使用的是JDBC-ODBC桥的连接方式,url是“jdbc:odbc:数据源名

       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//加载数据库的驱动类,sun.jdbc.odbc.JdbcOdbcDriverJDBC连接到ODBC的驱动类名

       Connection conn=DriverManager.getConnection(url);

       Statement stat=conn.createStatement();

//使用statement接口运行SQL语句

       String sql="INSERT INTO T_STUDENT(STUNO,STUNAME,STUSEX)VALUES('0032','黎哥','')";

 //处理SQL语句运行结果

       int i=stat.executeUpdate(sql);

       System.out.println("成功添加"+i+"");     

       stat.close(); 

       conn.close();

    //关闭数据源连接

}

}

 

 

 

 

package JDBC;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

 

 

public class Delect1 {

    public static void main(String[] args) throws Exception {

      

       String url="jdbc:odbc:DDSchool";

       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

       Connection conn=DriverManager.getConnection(url);

       Statement stat=conn.createStatement();

       String sql="DELETE FROM T_STUDENT WHERE STUSEX='男'";

       int i=stat.executeUpdate(sql);

       System.out.println("成功删除"+i+"行");

       stat.close();

       conn.close();

      

    }

   

}

 

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template