MySQL不指定库名使用JDBC连接

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DataBase {

public static Connection getConn() {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/", "root", "root");
System.out.println("success...");
}catch(Exception e){
e.printStackTrace();
}
return conn;

}
public static void main(String[] args) throws SQLException{
Connection conn = DataBase.getConn();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select t.* from lms34.roles r,test.test11 t");
while(rs.next()) {
System.out.println(rs.getString(1));
}

}
}

你可能感兴趣的:(MySQL,数据库,java)