Java创建数据库,找不到sun.jdbc.odbc.JdbcOdbcDriver驱动器
用Java编写程序,程序如下:importjava.sql.*;publicclassCreateTableBank{publicstaticvoidmain(Strin...
用Java编写程序,程序如下:
import java.sql.*;
public class CreateTableBank
{
public static void main(String[] args)
{
//String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb,*accdb)};DBQ=D:/javapro/Access/Bank.accdb";
String JDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB = "jdbc:odbc:Bank";
try
{
Class.forName(JDriver);
}
catch (java.lang.ClassNotFoundException e)
{
System.out.println("ForName:"+e.getMessage());
}
try
{
Connection con = DriverManager.getConnection(connectDB);
Statement stmt = con.createStatement();
String query1 = "create table Borrow("+"branch_name String,"+"loan_name Number,"+"customer_name String,"+"amount Number"+")";
String query2 = "create table Branch("+"branch_name String,"+"assets Number,"+"branch_city String"+")";
String query3 = "create table Customer("+"customer_name String,"+"street String,"+"customer_city String"+")";
String query4 = "create table Deposit("+"branch_name String,"+"account_number Number"+"customer_name String,"+"balance Number"+")";
stmt.executeUpdate(query1);
stmt.executeUpdate(query2);
stmt.executeUpdate(query3);
stmt.executeUpdate(query4);
stmt.close();
con.close();
}
catch (SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
}
编译没有问题,运行出现问题如下:
ForName:sun.jdbc.odbc.JdbcOdbcDriver
SQLException:No suitable driver found for jdbc:odbc:Bank
求指教 展开
import java.sql.*;
public class CreateTableBank
{
public static void main(String[] args)
{
//String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb,*accdb)};DBQ=D:/javapro/Access/Bank.accdb";
String JDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB = "jdbc:odbc:Bank";
try
{
Class.forName(JDriver);
}
catch (java.lang.ClassNotFoundException e)
{
System.out.println("ForName:"+e.getMessage());
}
try
{
Connection con = DriverManager.getConnection(connectDB);
Statement stmt = con.createStatement();
String query1 = "create table Borrow("+"branch_name String,"+"loan_name Number,"+"customer_name String,"+"amount Number"+")";
String query2 = "create table Branch("+"branch_name String,"+"assets Number,"+"branch_city String"+")";
String query3 = "create table Customer("+"customer_name String,"+"street String,"+"customer_city String"+")";
String query4 = "create table Deposit("+"branch_name String,"+"account_number Number"+"customer_name String,"+"balance Number"+")";
stmt.executeUpdate(query1);
stmt.executeUpdate(query2);
stmt.executeUpdate(query3);
stmt.executeUpdate(query4);
stmt.close();
con.close();
}
catch (SQLException e)
{
System.out.println("SQLException:"+e.getMessage());
}
}
}
编译没有问题,运行出现问题如下:
ForName:sun.jdbc.odbc.JdbcOdbcDriver
SQLException:No suitable driver found for jdbc:odbc:Bank
求指教 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询