环境配置:
首先下载安装配置MYSQL(教程很多),然后在去下载MYSQL驱动包,解压后会有一个名字类似mysql-connector-java-5.1.5-bin.jar的文件
将这个文件拷贝到%java_home%/lib文件夹下。
右键我的电脑->属性->高级->环境变量。在classpath的后面加上;%java_home%/lib/mysql-connector-java-5.1.5-bin.jar;
代码(执行查询类SQL语句):
<pre name="code" class="java">import java.sql.*;
public class ShowItems {
static private Connection conn;
static int cnt = 0;
public static void main(String args[]){
if(connect()){
String ss = "SELECT courses.courseNo,courses.Name,students.stuNo,students.Name FROM students RIGHT JOIN courselist ON students.stuNo = courselist.stuNo RIGHT JOIN Courses ON courselist.courseNo = courses.courseNo ORDER BY courses.courseNo,students.stuNo;";
ResultSet rs = executeQuery(ss);
sh