package com.zss.www;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import com.mysql.jdbc.Connection;

public class UseDadabase {

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/class";
String username="root";
String password="12345";
Connection conn=null;
Class.forName(driver);
conn=(Connection) DriverManager
.getConnection(url,username,password);
Statement stmt=null;
ResultSet rs=null;
stmt=(Statement) conn.createStatement();
rs=stmt.executeQuery("select*from student");
while(rs.next()){
System.out.println("name="+rs.getString(1));
System.out.println("age="+rs.getString(2));
}
rs.close();
stmt.close();
conn.close();


}

}

package com.zss.www;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import com.mysql.jdbc.Connection;

public class UseDadabase {

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/class";
String username="root";
String password="12345";
Connection conn=null;
Class.forName(driver);
conn=(Connection) DriverManager
.getConnection(url,username,password);
Statement stmt=null;
ResultSet rs=null;
stmt=(Statement) conn.createStatement();
rs=stmt.executeQuery("select*from student");
while(rs.next()){
System.out.println("name="+rs.getString(1));
System.out.println("age="+rs.getString(2));
}
rs.close();
stmt.close();
conn.close();


}

}

你可能感兴趣的:(哼)