package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestJDBC {
/**
* 入口函数
*
* @param arg
*/
public static void main(String arg[]) {
try {
Connection con = null; // 定义一个MYSQL链接对象
Class.forName("com.mysql.jdbc.Driver").newInstance(); // MYSQL驱动
con = DriverManager
.getConnection(
"jdbc:mysql://*/liveEpg?useUnicode=true&characterEncoding=UTF-8",
"root", "*"); // 链接本地MYSQL
Statement stmt; // 创建声明
stmt = con.createStatement();
// 查询数据并输出
String selectSql = "SELECT othChannelId FROM channel_info";
ResultSet selectRes = stmt.executeQuery(selectSql);
while (selectRes.next()) { // 循环输出结果集
String username = selectRes.getString("othChannelId");
System.out.println("username:" + username);
}
} catch (Exception e) {
System.out.print("MYSQL ERROR:" + e.getMessage());
}
}
}