使用Netbeans IDE将MySQL连接到Java
请问如何连接MySQL中的Java程序,请帮助我!使用Netbeans IDE将MySQL连接到Java,java,mysql,netbeans,Java,Mysql,Netbeans,请问如何连接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://1
你能给我一个演示,只是为了显示数据库上的记录,提前谢谢 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 );
}
试试看{
Class.forName(“com.mysql.jdbc.Driver”);//设置驱动程序
Connection connect=DriverManager.getConnection(“jdbc:mysql://127.0.0.1:3306“,”“,”“);//连接到数据库
语句st=connect.createStatement();
结果集rs=st.executeQuery(“选择*自”);
while(rs.next()){
系统输出打印(rs.getString(1));
}
}
捕获(例外e){
系统输出打印(e);
}
可能重复@RajavelD我无法理解那篇帖子