猿问

java 连接MYSQL 进行查询怎么修改

importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.Statement;
publicclassshiyan4{
	publicstaticfinalStringDBDRIVER="org.gjt.mm.mysql.Driver";
	publicstaticfinalStringDBURL="jdbc:mysql://localhost:3306/ace";
	publicstaticfinalStringDBUSER="root";
	publicstaticfinalStringDBPASS="root";
	publicstaticvoidmain(Stringargs[])throwsException{
		
		Connectionconn=null;
		
		Statementstmt=null;
		
		Class.forName(DBDRIVER);
		
		Stringsql="SELECTuser_nameFROMusers;";
		
		conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
		
		stmt=conn.createStatement();
		
		stmt.executeUpdate(sql);
		
		stmt.close();
		
		conn.close();
	}
}请问这样怎么修改才能正常的进行查询和在java上输出查询到的信息
慕标5832272
浏览 307回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答