标签:mysql rate rman set url int exce 名称 print
新建Java project名称为TextJDBC,在src文件夹下新建com.zss.www的包,并在包里建个class:UseDadabase
在MySQL中建立一个lb的库,并在其建立表:student,表中包涵name,age,sex
UseDadabase代码如下:
package com.zss.www; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import com.mysql.jdbc.Connection; public class UseDadabase { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub String driver="com.mysql.jdbc.Driver"; String url="jdbc:mysql://localhost:3306/lb"; String username="root"; String password="11"; Connection conn=null; Class.forName(driver); conn=(Connection) DriverManager .getConnection(url,username,password); Statement stmt=null; ResultSet rs=null; stmt=(Statement) conn.createStatement(); rs=stmt.executeQuery("select*from student"); while(rs.next()){ System.out.println("name="+rs.getString(1)); System.out.println("age="+rs.getString(2)); System.out.println("sex="+rs.getString(3)); } rs.close(); stmt.close(); conn.close(); } }
标签:mysql rate rman set url int exce 名称 print
原文地址:http://www.cnblogs.com/bgd150809319/p/6648884.html