我想问一下如何在MySQL中连接Java程序,请帮帮我! 您能给我一个演示来显示数据库上的记录吗?提前谢谢!
最佳答案
127.0.0.1:3306
取决于您数据库的设置
确保在库中添加 MySQL JDBC 驱动程序
然后尝试这个代码..
try{
Class.forName("com.mysql.jdbc.Driver"); // to set the driver
Connection connect = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306", "<Database username>", "<Database password>"); // connect to database
Statement st = connect.createStatement();
Resultset rs = st.executeQuery( "SELECT * FROM <tablename>" );
while( rs.next() ){
System.out.print( rs.getString(1) );
}
}
catch( Exception e ){
System.out.print( e );
}
关于java - 使用 Netbeans IDE 将 MySQL 连接到 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24487057/