eclipse 如何连接数据库(mysql)
2014-07-12 16:22
417 查看
本文前两天突发奇想把自己的所有的账号都放到数据库中,因为平时喜欢逛论坛,可是发现自己还不会使用数据库,于是乎想到用office自带的ACCSE搞定,瞬间就打开了右键新建了一个ACCSE,然后各种建表的过程。。。。。
写好之后,发现电脑中找不到数据源连接的按钮,于是上网百度,发现很多win7系统自动把这个选项隐藏了
下面的动作将其调出来,电脑下方菜单栏中中鼠标右键属性,然后选择开始菜单---》自定义----》系统管理工具选择显示,ok
在开始菜单中找到这个选项之后,点击进入,找到数据源ODBC选项,然后选择添加,发现根本找不到ACCSE数据源,瞬间崩溃。。。。。。。。。。。。。。
从网上找到攻略,发现世间还是有爱的
方法就是找到C:\Windows\SysWOW64\odbcad32.exe,双击进去就和正常的完全一样了,然后很高兴的这么干了,代码也欢天喜地的写了,代码如下:
import java.sql.*;
class s{
public static void main(String args[]){
// String driver = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/zxc";
String user="root";
String password="zxcv";
String ls_1="select * from second_sql where 编号=1";//"select firstname from employee";
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序 ,其实JDBC驱动程序有四种
//Class.forName(driver);
Connection con=DriverManager.getConnection(url, user, password);//建立连接
Statement stmt=con.createStatement();//执行SQL
ResultSet result=stmt.executeQuery(ls_1);
System.out.print("编号 ");
System.out.print("password ");
System.out.print("lastname ");
System.out.print("firstname ");
System.out.print("age ");
System.out.print("address ");
System.out.print("city ");
while(result.next()){
System.out.println();
System.out.print(result.getInt(1)+" | ");
System.out.print(result.getString(2)+" | ");
System.out.print(result.getString(3)+" | ");
System.out.print(result.getString(4)+" | ");
System.out.print(result.getString(5)+" | ");
System.out.print(result.getString(6)+" | ");
System.out.println(result.getString(7)+" | ");
System.out.println();
}
result.close();
stmt.close();
con.close();
}catch(SQLException sqle){
System.out.println(1+sqle.toString());
}
catch(Exception e){
System.out.println(2+e.toString());
}
}
}
点击运行,瞬间我就
何解??????????、
出现的错误是DSN的类型错误,从网上baidu之后,发现很多人和我的错误都一样,仔细看了之后说的是,我的jdk和系统是64位的,用的数据库却是32位的,为了证明这句话是错误的我还特意看了一下自己的ACCSEE也就是office是多少位的。。。。。
看的方法网上很多,突然间发现别人说的真对,我的就是32位的
没有办法了,要么重装系统???
我去。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
必须不行啊,果断重新装一个数据库,从网上下载了一个mysql,我的版本是mysql-installer-community-5.7.3.0-m13.2063434697,装了之后发现太复杂了,不会用,最后在我们实验室的大神指导下,慢慢的搞定了,程序也随之稍微做了调整,
代码如下:
import java.sql.*;
class s{
public static void main(String args[]){
String driver = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/zxc";
String user="root";
String password="zxcv";
String ls_1="select * from second_sql where 编号=1";//"select firstname from employee";
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序 ,其实JDBC驱动程序有四种
Class.forName(driver);
Connection con=DriverManager.getConnection(url, user, password);//建立连接
Statement stmt=con.createStatement();//执行SQL
ResultSet result=stmt.executeQuery(ls_1);
System.out.print("编号 ");
System.out.print("password ");
System.out.print("lastname ");
System.out.print("firstname ");
System.out.print("age ");
System.out.print("address ");
System.out.print("city ");
while(result.next()){
System.out.println();
System.out.print(result.getInt(1)+" | ");
System.out.print(result.getString(2)+" | ");
System.out.print(result.getString(3)+" | ");
System.out.print(result.getString(4)+" | ");
System.out.print(result.getString(5)+" | ");
System.out.print(result.getString(6)+" | ");
System.out.println(result.getString(7)+" | ");
System.out.println();
}
result.close();
stmt.close();
con.close();
}catch(SQLException sqle){
System.out.println(1+sqle.toString());
}
catch(Exception e){
System.out.println(2+e.toString());
}
}
}
当然没有把用我的建的账号密码的那张表做实验了,随便添加的一张表!!!!!
到了mysql的使用稍微需要说的一点是,需要安装一个连接器,我安装的是mysql-connector-java-5.0.5,这个解压之后,我放在了D盘中,把其中的jar问价的路径添加到系统中的classpath下,具体添加的方法很简单,就不做脑残介绍了
使用eclipse还需要添加外部引用包,右击工程文件,选择properties----》java Build Path------》Libraries------》Add External JARs ,剩下的就是等着喝茶庆功酒OK了
写好之后,发现电脑中找不到数据源连接的按钮,于是上网百度,发现很多win7系统自动把这个选项隐藏了
下面的动作将其调出来,电脑下方菜单栏中中鼠标右键属性,然后选择开始菜单---》自定义----》系统管理工具选择显示,ok
在开始菜单中找到这个选项之后,点击进入,找到数据源ODBC选项,然后选择添加,发现根本找不到ACCSE数据源,瞬间崩溃。。。。。。。。。。。。。。
从网上找到攻略,发现世间还是有爱的
方法就是找到C:\Windows\SysWOW64\odbcad32.exe,双击进去就和正常的完全一样了,然后很高兴的这么干了,代码也欢天喜地的写了,代码如下:
import java.sql.*;
class s{
public static void main(String args[]){
// String driver = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/zxc";
String user="root";
String password="zxcv";
String ls_1="select * from second_sql where 编号=1";//"select firstname from employee";
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序 ,其实JDBC驱动程序有四种
//Class.forName(driver);
Connection con=DriverManager.getConnection(url, user, password);//建立连接
Statement stmt=con.createStatement();//执行SQL
ResultSet result=stmt.executeQuery(ls_1);
System.out.print("编号 ");
System.out.print("password ");
System.out.print("lastname ");
System.out.print("firstname ");
System.out.print("age ");
System.out.print("address ");
System.out.print("city ");
while(result.next()){
System.out.println();
System.out.print(result.getInt(1)+" | ");
System.out.print(result.getString(2)+" | ");
System.out.print(result.getString(3)+" | ");
System.out.print(result.getString(4)+" | ");
System.out.print(result.getString(5)+" | ");
System.out.print(result.getString(6)+" | ");
System.out.println(result.getString(7)+" | ");
System.out.println();
}
result.close();
stmt.close();
con.close();
}catch(SQLException sqle){
System.out.println(1+sqle.toString());
}
catch(Exception e){
System.out.println(2+e.toString());
}
}
}
点击运行,瞬间我就
何解??????????、
出现的错误是DSN的类型错误,从网上baidu之后,发现很多人和我的错误都一样,仔细看了之后说的是,我的jdk和系统是64位的,用的数据库却是32位的,为了证明这句话是错误的我还特意看了一下自己的ACCSEE也就是office是多少位的。。。。。
看的方法网上很多,突然间发现别人说的真对,我的就是32位的
没有办法了,要么重装系统???
我去。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
必须不行啊,果断重新装一个数据库,从网上下载了一个mysql,我的版本是mysql-installer-community-5.7.3.0-m13.2063434697,装了之后发现太复杂了,不会用,最后在我们实验室的大神指导下,慢慢的搞定了,程序也随之稍微做了调整,
代码如下:
import java.sql.*;
class s{
public static void main(String args[]){
String driver = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/zxc";
String user="root";
String password="zxcv";
String ls_1="select * from second_sql where 编号=1";//"select firstname from employee";
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序 ,其实JDBC驱动程序有四种
Class.forName(driver);
Connection con=DriverManager.getConnection(url, user, password);//建立连接
Statement stmt=con.createStatement();//执行SQL
ResultSet result=stmt.executeQuery(ls_1);
System.out.print("编号 ");
System.out.print("password ");
System.out.print("lastname ");
System.out.print("firstname ");
System.out.print("age ");
System.out.print("address ");
System.out.print("city ");
while(result.next()){
System.out.println();
System.out.print(result.getInt(1)+" | ");
System.out.print(result.getString(2)+" | ");
System.out.print(result.getString(3)+" | ");
System.out.print(result.getString(4)+" | ");
System.out.print(result.getString(5)+" | ");
System.out.print(result.getString(6)+" | ");
System.out.println(result.getString(7)+" | ");
System.out.println();
}
result.close();
stmt.close();
con.close();
}catch(SQLException sqle){
System.out.println(1+sqle.toString());
}
catch(Exception e){
System.out.println(2+e.toString());
}
}
}
当然没有把用我的建的账号密码的那张表做实验了,随便添加的一张表!!!!!
到了mysql的使用稍微需要说的一点是,需要安装一个连接器,我安装的是mysql-connector-java-5.0.5,这个解压之后,我放在了D盘中,把其中的jar问价的路径添加到系统中的classpath下,具体添加的方法很简单,就不做脑残介绍了
使用eclipse还需要添加外部引用包,右击工程文件,选择properties----》java Build Path------》Libraries------》Add External JARs ,剩下的就是等着喝茶庆功酒OK了
相关文章推荐
- 用eclipse连接MySQL的一点心得体会,如何加载数据库驱动
- 在jsp中如何有JDBC连接各种数据库之MySQL
- MySQL 如何从其他主机连接数据库
- window xp PHP5.2.17 apache2.2 mysql eclipse 数据库连接(mysql,oracle10)
- 如何正确获得mysql,access的ADO连接字符串,并使用该连接字符串连接数据库
- Jmeter如何连接数据库Mysql
- 如何使用三层框架开发 JDBC 连接 Mysql 数据库
- SpringMVC+Hibernate将连接oracle的数据库换成MySQL,报错如何解决
- 如何创建本地数据库MySQL并连接JDBC
- Eclipse开发Java之连接数据库MySql
- 如何设置mysql 数据库连接超时
- rsyslog的ommsql模块如何连接MYSQL的非标准数据库端口?
- 如何使用navicat for mysql连接本地数据库,并且导入数据文件
- 如何用eclipse将数据库oracle数据相连接,实现查询数据库中的信息以及更改添加表中内容
- eclipse中数据库连接mysql配置
- Eclipse如何连接SQL Server 2005数据库
- Mysql 与eclipse 数据库的连接
- mysql+jsp,在jsp页面连接了数据库,已成功获取数据库字段,请问如何取到当前用户对应的信息
- Jmeter如何连接数据库Mysql
- 初试数据库--eclipse连接数据库mysql,非常简单的入门!