package com.chinasoft.thr.shop;
import java.sql.*;public class JDBC { public static final String DRIVER = "com.mysql.jdbc.Driver"; public static final String URL = "jdbc:mysql://122.114.147.148:3306/ccc"; public static final String USERNAME = "java0613"; public static final String PASSWORD = "java0613"; public static void main(String[] args) throws SQLException, ClassNotFoundException { Connection conn = null; //每一个Connection对象表示一个数据库连接对象 Statement stat = null; Class.forName(DRIVER);//加载驱动程序 conn=DriverManager.getConnection(URL,USERNAME,PASSWORD); stat = conn.createStatement();//找到接口 String sql = "select*from vip where v_gra='郑威威'";//查询语句 ResultSet rs=stat.executeQuery(sql);//查询 //将查询出的结果输出 while (rs.next()) { String v_gra=rs.getString(1); String v_jif=rs.getString(2); String v_dis=rs.getString(3); System.out.println("姓名:"+v_gra+",积分:"+v_jif+",折扣:"+v_dis); } rs.close(); stat.close(); conn.close(); }}