首页 > 代码库 > application下的JDBC操作

application下的JDBC操作

package com.zss.www;
import java.sql.DriverManager;
import java.sql.ResultSet;

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

public class UseDatabase {
 public static void main(String[] args)throws Exception{
 String driver="com.mysql.jdbc.Driver";
 String url="jdbc:mysql://localhost:3306/information";
 String username="root";
 String password="110119";
 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("schoolId="+rs.getString(1));
  System.out.println("name="+rs.getString(2));
 }
 rs.close();
 stmt.close();
 conn.close();
   if (conn!=null)
  System.out.println("Success!");
 else
  System.out.println("failure!");
 
 }

}

 

application下的JDBC操作