Demo entry 6687268

ja

   

Submitted by lu on Dec 27, 2017 at 04:20
Language: Java. Code size: 867 Bytes.

package org.connectiondemo;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectionJDBC {

	/**
	 * @param args
	 */
	//Çý¶¯³ÌÐò¾ÍÊÇ֮ǰÔÚclasspathÖÐÅäÖõÄJDBCµÄÇý¶¯³ÌÐòµÄJAR °üÖÐ
	public static final String DBDRIVER = "com.mysql.jdbc.Driver";
	//Á¬½ÓµØÖ·ÊÇÓɸ÷¸öÊý¾Ý¿âÉú²úÉ̵¥¶ÀÌṩµÄ£¬ËùÒÔÐèÒªµ¥¶À¼Çס
	public static final String DBURL = "jdbc:mysql://localhost:3306/test";
	//Á¬½ÓÊý¾Ý¿âµÄÓû§Ãû
	public static final String DBUSER = "root";
	//Á¬½ÓÊý¾Ý¿âµÄÃÜÂë
	public static final String DBPASS = "";
	
	
	public static void main(String[] args) throws Exception {
		Connection con = null; //±íʾÊý¾Ý¿âµÄÁ¬½Ó¶ÔÏó
		Class.forName(DBDRIVER); //1¡¢Ê¹ÓÃCLASS Àà¼ÓÔØÇý¶¯³ÌÐò
		con = DriverManager.getConnection(DBURL,DBUSER,DBPASS); //2¡¢Á¬½ÓÊý¾Ý¿â
		System.out.println(con);
		con.close(); // 3¡¢¹Ø±ÕÊý¾Ý¿â
	}

}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).