gpt4 book ai didi

java if语句字符串比较

转载 作者:行者123 更新时间:2023-12-02 04:13:52 24 4
gpt4 key购买 nike

    package canlitahmin;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class baglanti {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/canlitahmin";

// Database credentials
static final String USER = "root";
static final String PASS = "";
public static List<Integer> id = new ArrayList<Integer>();
public static List<Integer> evgol = new ArrayList<Integer>();
public static List<Integer> kuralid = new ArrayList<Integer>();
public static List<String> kural = new ArrayList<String>();
public static List<Integer> depgol = new ArrayList<Integer>();
public static List<Integer> dakika = new ArrayList<Integer>();

public static void main(String[] args) {


Connection conn = null;
Statement stmt = null;
Statement stmt2 = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);

//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
stmt2 = conn.createStatement();
String sql;
String sql2;
sql = "SELECT id, evgol, depgol, dk FROM maclar";
sql2="SELECT id,kural from kurallar";
ResultSet rs = stmt.executeQuery(sql);
ResultSet rs2 = stmt2.executeQuery(sql2);
int i=0;
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
id.add(rs.getInt("id"));
evgol.add(rs.getInt("evgol"));
depgol.add(rs.getInt("depgol"));
dakika.add(rs.getInt("dk"));

//Display values
System.out.print("ID: " + id.get(i));
System.out.print(", Evgol: " + evgol.get(i));
System.out.print(", Depgol: " + depgol.get(i));
System.out.println(", dakika: " + dakika.get(i));
i++;
}
int k=0;
while(rs2.next()){
//Retrieve by column name
kuralid.add(rs2.getInt("id"));
kural.add(rs2.getString("kural"));

//Display values
System.out.print("KURALID: " + kuralid.get(k));
System.out.println(", KURAL: " + kural.get(k));
k++;
}

for(int l=0;l<id.size();l++){
int BYTG=evgol.get(l);
int DEPTG=depgol.get(l);

/* int DK=dakika.get(l);
int MACKODLARI=id.get(l);*/

for(int j=0;j<kuralid.size();j++){

###if(kural.get(j))###{ // ERROR**********************************
double a=BYTG+DEPTG+0.5;
int b=BYTG+DEPTG;
String kural="Tahmin:"+a+" üstü ve "+b+" üstü";
System.out.println(kural);
}}
}
//STEP 6: Clean-up environment
rs.close();
rs2.close();
stmt.close();
stmt2.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end FirstExample

java if语句字符串比较。我的数据库数据进入“kural.get(j)”但 kural.get(j) 错误。因为它的字符串变量。问题: String a=b>0 && c>0 -- if(a) 我如何使用? if 中带变量的字符串代码

最佳答案

这可以通过 JavaCompiler 以编程方式完成和 javax.tools package

作为相关问题,请参阅How do I programmatically compile and instantiate a Java class?

解决方案是相同的。

关于java if语句字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33528903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com