当前位置: 技术问答>java相关
我连接ACCESS数据库出现了问题?
来源: 互联网 发布时间:2015-02-08
本文导语: 我用的是ACCESS数据库用jdbc-odbc连接数据库时出现No suitable driver?? 具体程序如下: import java.awt.*; import java.applet.*; import java .sql.*; public class demo extends Applet { TextField textField; public void init() { resize(400,300); } ...
我用的是ACCESS数据库用jdbc-odbc连接数据库时出现No suitable driver??
具体程序如下:
import java.awt.*;
import java.applet.*;
import java .sql.*;
public class demo extends Applet
{
TextField textField;
public void init()
{
resize(400,300);
}
public boolean action(Event event,Object arg)
{repaint();
return true;}
public void paint(Graphics g) //此方法用于显示输出
{
this.setBackground(Color.lightGray ); //定义背景颜色
this.setForeground(Color.red); //定义前景颜色
g.drawString("结果",100,140);
//210.76.0.161
String url = "jdbc:odbc:demo";
String ls_1="select * from aa";
try
{
g.drawString("加载驱动程序.......",40,40);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); //加载驱动程序
g.drawString("加载成功.",40,60);
g.drawString(url,240,60);
//建立连接
g.drawString("正在连接数据库...",40,80);
Connection con=DriverManager.getConnection(url,"","");
g.drawString("连接成功!!",40,90);
//执行SQL
StringBuffer qry=new StringBuffer(1024);
Statement stmt=con.createStatement();
ResultSet result=stmt.executeQuery(ls_1); //返回结果
ResultSetMetaData aa1=result.getMetaData();
int ii=aa1.getColumnCount();
g.drawString("ii="+ii,100,70);
g.drawString("kjdljakj"+aa1.getColumnName(1),100,90);
while(result.next()){
for (int i1=1;i1
具体程序如下:
import java.awt.*;
import java.applet.*;
import java .sql.*;
public class demo extends Applet
{
TextField textField;
public void init()
{
resize(400,300);
}
public boolean action(Event event,Object arg)
{repaint();
return true;}
public void paint(Graphics g) //此方法用于显示输出
{
this.setBackground(Color.lightGray ); //定义背景颜色
this.setForeground(Color.red); //定义前景颜色
g.drawString("结果",100,140);
//210.76.0.161
String url = "jdbc:odbc:demo";
String ls_1="select * from aa";
try
{
g.drawString("加载驱动程序.......",40,40);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); //加载驱动程序
g.drawString("加载成功.",40,60);
g.drawString(url,240,60);
//建立连接
g.drawString("正在连接数据库...",40,80);
Connection con=DriverManager.getConnection(url,"","");
g.drawString("连接成功!!",40,90);
//执行SQL
StringBuffer qry=new StringBuffer(1024);
Statement stmt=con.createStatement();
ResultSet result=stmt.executeQuery(ls_1); //返回结果
ResultSetMetaData aa1=result.getMetaData();
int ii=aa1.getColumnCount();
g.drawString("ii="+ii,100,70);
g.drawString("kjdljakj"+aa1.getColumnName(1),100,90);
while(result.next()){
for (int i1=1;i1