jdbc my sql 데이터베이스 정보 조회

1684 단어 자바
package com;

import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.ResultSet;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

import sun.print.resources.serviceui;

public class test {
	public static void main(String[] args) {
		try {
			/*Class.forName("com.mysql.jdbc.Driver");
			
			String conString="jdbc:mysql://localhost:3306/student_db";
			Connection connection=(Connection) DriverManager.getConnection(conString,"root","");
			Statement statement=(Statement) connection.createStatement();
			boolean resultSet=statement.execute("insert into student\r
" + "VALUES(\"201215123\",\" \",\" \",18,\"cs\");");*/ /*while (resultSet.next()) { System.out.println(resultSet.getString("Sname")); }*/ /*connection.close();*/ DriverManager.deregisterDriver(new com.mysql.jdbc.Driver()); Connection connection=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/student_db"); PreparedStatement preparedStatement=(PreparedStatement) connection.prepareStatement("select * from student"); ResultSet resultSet=preparedStatement.executeQuery(); while (resultSet.next()){ System.out.println(resultSet.getString("sname")); } resultSet.close(); preparedStatement.close(); connection.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

좋은 웹페이지 즐겨찾기