Topic: 连接access出错.

  Print this page

1.连接access出错. Copy to clipboard
Posted by: justforu
Posted on: 2005-04-11 09:48

import java.io.*;
import java.sql.*;
class BookQuery
{
  public static void main(String args[])
  {
    try
    {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException ce)
    {
      System.out.println("SQLException"+ce.getMessage());
    }
    try
    {
      Connection con=DriverManager.getConnection("jdbc.odbc:bookbase");
      Statement stmt=con.createStatement();
      ResultSet rs=stmt.executeQuery("select * from bookTab");
      while(rs.next())
      {
        System.out.println(
        "书号"+rs.getInt(1)+"\t"+
        "书名"+rs.getString(2)+"\t"+
        "作者"+rs.getString(3)+"\t"+
        "单价"+rs.getFloat(4));
      }
      stmt.close();
      con.close();
    }
    catch(SQLException e)
    {
      System.out.println("SQLException:"+e.getMessage());
    }
  }
}

报错为:SQLException: No Suitable driver
why ??

2.Re:连接access出错. [Re: justforu] Copy to clipboard
Posted by: why
Posted on: 2005-04-11 10:55

Please don't double post!Sad

Check the book you're reading or do a search on Google first...

9. What causes the "No suitable driver" error?
http://java.sun.com/products/jdbc/faq.html#9


Actually, it is not difficult to guess ... typo typo typo
DriverManager.getConnection("jdbc.odbc:bookbase");

3.Re:连接access出错. [Re: justforu] Copy to clipboard
Posted by: justforu
Posted on: 2005-04-11 11:42

sorry ,i just want to get response as soon as possible.
as a beginer ,i have searched many times on web, but i can't get the detail of connect to database.

after read the FAQ,i have 2 problem
need jdbc driver ? but I use c:\j2sdk1.4.2, should also have no URl problem
if need more,please paste them and give the install processing

give me a detail ,not a URL, thank u
Beginner just need detail to learn himseft next time.

4.Re:连接access出错. [Re: justforu] Copy to clipboard
Posted by: justforu
Posted on: 2005-04-11 11:50

if connect to oracle ?
need oracle jdbc driver or have been contain in j2sdk ???

5.Re:连接access出错. [Re: justforu] Copy to clipboard
Posted by: czl1314
Posted on: 2005-04-11 15:07

My English is not so well that i can't read it,can you speek chinese ?
i only want to study how to connect to database ,not english .

6.Re:连接access出错. [Re: justforu] Copy to clipboard
Posted by: why
Posted on: 2005-04-11 19:37

czl1314:
Sorry, I don't have time and patience to write in details and in Chinese.
And I believe that I could not write better or clearer than those being published.
Find your favorite book written in Chinese to read.
Good luck.

BTW, you could write in Chinese and your English looks fine.Smile



justforu:
Plesae make good use of the editing features of our forum

The details could be found in the FAQ.
And I guess I had pinpointed to the problem you had: typo!
It is jdbc:odbc:bookbase (a colon between jdbc and odbc), and not jdbc.odbc:bookbase (a dot).

No, you don't need a driver if you are using the ODBC bridge -- you could use another ODBC bridge though.Smile
Yes, you need to look for a JDBC driver for any other database.

7.Re:连接access出错. [Re: justforu] Copy to clipboard
Posted by: justforu
Posted on: 2005-04-11 23:33

thank u !!~~


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923