Java如何连接mysql数据库?并且去得表中的内容?谢谢。

解决方案 »

  1.   

    用jdbc桥连,在eclipse下编好在连接!
      

  2.   

    自己搜,多的很。如:http://www.xue5.com/itedu/200707/134068.html
      

  3.   

    不会写,才学:import java.sql.*;
    public class TestJdbc01 {
    public static void main(String[] args) throws Exception{
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("show tables;");
    while(rs.next()){
    System.out.println("hah");
    System.out.println(rs.getInt("compy"));
    }
    rs.close();
    s.close();
    conn.close();
    }
    }
      

  4.   

    到底是用sql语法的select 还是mysql 的show tables;  ?
      

  5.   

    s.executeQuery("show tables;");
    这里写sql
    select * from 表名
      

  6.   

    show tables是显示当前数据库的所有表明
    要取数据用select
      

  7.   

    现在的jdbc已经变为org.gjt.mm.mysql.Driver而不再是com.mysql.jdbc.Driver
    库不包含在jdk中需要你下载并设置好路径
      

  8.   

    但是如果写select 就执行不了while了?
      

  9.   

    用select完全一样啊,一样可以写你的while
      

  10.   

    不是jre的path,是你project编译时需要的buildpath和之后你运行时的classpath