当前位置: 技术问答>java相关
怎么连access??地方下相关的jdbc??
来源: 互联网 发布时间:2015-05-01
本文导语: 谢谢 | import java.sql.*; Connection connection=null; PreparedStatement statement=null; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection=DriverManager.getConnection("jdbc:odbc:testAccess","sa",""...
谢谢
|
import java.sql.*;
Connection connection=null;
PreparedStatement statement=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection=DriverManager.getConnection("jdbc:odbc:testAccess","sa","");
Enumeration eDri = DriverManager.getDrivers();
while(eDri.hasMoreElements())
System.out.println("驱动程序:" + eDri.nextElement().toString());
}
catch(Exception e)
{
e.printStackTrace();
}
try{
String sql="select * from people";
statement=connection.prepareStatement(sql);
ResultSet result=statement.executeQuery();
while(result.next())
{
int nid=result.getInt("id");
String strid=new String("id "+nid);
System.out.println(strid);
String name=result.getString("name");
System.out.println("name "+name);
String sex=result.getString("sex");
System.out.println("sex "+sex);
// int age=result.getInt("age");
// String strAge=new String(""+age);
// System.out.println("age "+strAge);
String phone=result.getString("phone");
System.out.println("phone "+phone);
String other=result.getString("other");
System.out.println("other "+other);
}
result.close();
statement.close();
}catch(Exception e)
{
System.out.println(e.toString());
}
Connection connection=null;
PreparedStatement statement=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection=DriverManager.getConnection("jdbc:odbc:testAccess","sa","");
Enumeration eDri = DriverManager.getDrivers();
while(eDri.hasMoreElements())
System.out.println("驱动程序:" + eDri.nextElement().toString());
}
catch(Exception e)
{
e.printStackTrace();
}
try{
String sql="select * from people";
statement=connection.prepareStatement(sql);
ResultSet result=statement.executeQuery();
while(result.next())
{
int nid=result.getInt("id");
String strid=new String("id "+nid);
System.out.println(strid);
String name=result.getString("name");
System.out.println("name "+name);
String sex=result.getString("sex");
System.out.println("sex "+sex);
// int age=result.getInt("age");
// String strAge=new String(""+age);
// System.out.println("age "+strAge);
String phone=result.getString("phone");
System.out.println("phone "+phone);
String other=result.getString("other");
System.out.println("other "+other);
}
result.close();
statement.close();
}catch(Exception e)
{
System.out.println(e.toString());
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。