application下的JDBC应用

 

 

 

package com.sss.www;

 

import java.sql.DriverManager;

import java.sql.ResultSet;

 

import com.mysql.jdbc.Connection;

import com.mysql.jdbc.Statement;

 

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/student";

       String username = "root";

       String password = "zch.8023";

       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 message");

while (rs.next()){

System.out.println("name="+rs.getString(1));

System.out.println("name="+rs.getString(2));

 

}

rs.close();

stmt.close();

conn.close();

 

}}

你可能感兴趣的:(application下的JDBC应用)