package jdbc;
import java.sql.*;
public class Mysql{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
//加载MYSQL JDBC驱动程序
System.out.println("Success loading Mysql Driver!");
}
catch (Exception e)
{
System.out.print("Error loading Mysql Driver!"); e.printStackTrace();
}
try
{
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/XXXXdb","root","password");
System.out.println("Success connect Mysql server!");
//select code
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from am_api");
//am_api为表的名称
while (rs.next())
{
System.out.println(rs.getString("API_NAME"));
//API_NAME是表am_api的一个字段
}
}
catch (Exception e)
{
System.out.print("get data error!");
e.printStackTrace();
}
}
}
import java.sql.*;
public class Mysql{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
//加载MYSQL JDBC驱动程序
System.out.println("Success loading Mysql Driver!");
}
catch (Exception e)
{
System.out.print("Error loading Mysql Driver!"); e.printStackTrace();
}
try
{
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/XXXXdb","root","password");
System.out.println("Success connect Mysql server!");
//select code
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from am_api");
//am_api为表的名称
while (rs.next())
{
System.out.println(rs.getString("API_NAME"));
//API_NAME是表am_api的一个字段
}
}
catch (Exception e)
{
System.out.print("get data error!");
e.printStackTrace();
}
}
}