标签:127.0.0.1 roo etc exec manager demo1 执行sql 语句 技术分享
简单地JDBC小实例
package com.javaJDBCTest; import java.sql.DriverManager; import java.sql.ResultSet; import com.mysql.jdbc.Connection; import com.mysql.jdbc.Statement; public class JDBCTestDemo1 { public static void main(String args[]) throws Exception { //加载驱动类 Class.forName("com.mysql.jdbc.Driver"); //通过DriverManager获取数据库连接 String url = "jdbc:mysql://127.0.0.1/TestDB"; String user = "root"; String password = "ddddd"; Connection connection = (Connection) DriverManager.getConnection(url, user, password); //通过connection对象获取Statement对象,执行SQL语句 Statement statement = (Statement)connection.createStatement(); ResultSet resultSet = statement.executeQuery("select * from customers"); //操作ResultSet while(resultSet.next()) { System.out.println(resultSet.getString("cust_name")); } //关闭数据库连接 resultSet.close(); statement.close(); connection.close(); } }
这是MySQL表
连接成功,获取表数据:
标签:127.0.0.1 roo etc exec manager demo1 执行sql 语句 技术分享
原文地址:http://www.cnblogs.com/dreamyu/p/6954081.html