package com.bsonline.test.mysqlTest;
imp
imp
imp
imp
imp
public class MySQLTest {
private static final String URL="jdbc:mysql://localhost/bsonline";
private static final String USERNAME="root";
private static final String PASSWORD="123456";
/**
*@author: zhangjp
* @throws ClassNotFoundException
*@功能:
*@公用:
*@date:Apr 30, 2010 4:34:19 PM
**/
public static void main(String[] args) throws ClassNotFoundException {
try {
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//获得连接
Connection conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
//sql语句
String sql = "select * from system where id =?";
//获得prepareStatement对象,编译sql
PreparedStatement ps=conn.prepareStatement(sql);
//设置查询值
ps.setInt(1, 1);
//执行sql,获得结果集
ResultSet rs = ps.executeQuery();
//遍历结果集
while(rs.next()){
System.out.println(rs.getInt("id")+ " "+rs.getString("username")+" "+rs.getString("password"));
}
//
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}