首页 > 代码库 > jdbc连接mysql

jdbc连接mysql

package com.lianxi;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/boooks","root","tiger");
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from tb_user");
        while(rs.next()){
           System.out.print(rs.getInt(1)+"\t");
           System.out.print(rs.getString(2)+"\t");
           System.out.print(rs.getString(3)+"\t");
           System.out.println(rs.getString(4));
        }
        rs.close();
        st.close();
        conn.close();
    }
    }

 

jdbc连接mysql