public class test {
public static void main(String[] args) {
String[] arr = {"0 1.2.3.4","a b.c.d.e"};
System.out.println(arr[0].split(".")[2]);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用java 8。
预期输出是3。
我在 Mysql 中创建了一个表,使用
Create table
(
id int auto_increment,
us varchar(100),
ps varchar(1000)
);
Run Code Online (Sandbox Code Playgroud)
并使用 java 通过我的 GUI 应用程序添加值:
我使用以下方法将值添加到数据库中:
public static void Mysql(String u, String p) throws NoSuchAlgorithmException, InvalidKeySpecException
{
String hashpass=passhash(p);//throws declaration for this statement
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bs","root","root");
String query = " insert into login (id,us,ps)"
+ " values (?,?, ?)";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from login");
int id=0;
while(rs.next())
{
id= rs.getInt(1);
}
PreparedStatement preparedStmt = con.prepareStatement(query);
preparedStmt.setInt(1, id++); //I don't want this method because …Run Code Online (Sandbox Code Playgroud)