java if statement string comparison - java

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 statement string comparison. my database datas get in "kural.get(j)"
but kural.get(j) error. because its string variable.
Question: String a=b>0 && c>0 -- if(a) how i use? String code in if with variable

This can be done programmatically with the JavaCompiler and the javax.tools package
As a related question, see How do I programmatically compile and instantiate a Java class?
The solution is the same.

You cannot easily do that with Strings. What you can do is make an interface like this
interface IntIntPredicate {
public boolean test(int i, int j);
}
Then you can do (in Java 8):
IntIntPredicate a = (i, j) -> i == 1 && j <= 2;
IntIntPredicate b = (i, j) -> i <= 0 && j == 2;
Then later you can do:
if (a.test(i, j)) {
// do something
} else if (b.test(i, j)) {
// do something else
}
This is possible in earlier versions of Java, but the syntax is more clumsy.
If it is necessary for the data to be entered as a String, it would probably not be too difficult to write a method to parse a String (treating i and j as the first and second arguments) and return an IntIntPredicate
public static IntIntPredicate parse(String x) {
// This is going to require a lot of work, but
// there are many questions on this site about how
// to parse expressions such as "(2 + 3) * 9"
}

You could make a method, like:
boolean predicate(i,j) {
if (i==1 and j <=2) {
return true;
}
return false;
}
And then invoke the method like this:
if (predicate(i,j)) {
System.out.println("a");
}

You can also used ScriptEngine, but you need to translate the logic to a scripting language like Javascript.
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
/**
*
* #author afshin
*/
public class Blah {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws ScriptException {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
int i = 1;
int j = 1;
String a = i + "==1 && " + j +"<=2";
String b= i + "<=0 && " + j+"==2";
if (((Boolean) engine.eval(a)))
System.out.println("a is true");
if (((Boolean) engine.eval(b)))
System.out.println("b is true");
}
}

Related

How to pass array of integer to Informix stored procedure

In Java, how do I pass values of type set to a procedure. This seems too basic, but I can't solve it, I spent days searching sample Java code on how to pass set values to Informix procedure.
Tools
IBM Informix Dynamic Server Version 12.10.FC13
JDBC 4.10.14, 4.50.7
Java version "1.8.0_172"
Informix procedure
create procedure sp_demo_set_arg(
arg1 set(integer not null)
)
...
end procedure
Java code
#Override
public Integer callProcedure(List<Integer> listOfId) {
String sql = "{ call sp_demo_set_arg(?) }";
#SuppressWarnings("rawtypes")
java.util.HashSet arg1 = new HashSet();
Integer intObject;
int i;
for (i=1; i <= 3; i++)
{
intObject = new Integer(i);
arg1.add(intObject);
}
Connection conn = null;
try {
conn = dataSource.getConnection();
CallableStatement stmt = conn.prepareCall(sql);
stmt.setObject(1, arg1);
stmt.executeUpdate();
return 0;
} catch (SQLException e) {
e.printStackTrace();
}
return 1;
}
Stacktrace
...
java.sql.SQLException: Routine (sp_demo_set_arg) can not be resolved.
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3133)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3417)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2324)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2249)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:850)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:230)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:1054)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:396)
at
...
Your java code may fail with an -674 "Routine can not be resolved" error because the server may not know the parameter type at execution.
Try giving it some 'hints' changing '?' for a '?::SET(integer not null)'
Something like:
D:\Infx\work\Java>cat t2.java
import java.sql.*;
import java.util.*;
public class t2 {
public static void main( String [] args ) {
Connection conn = null;
ResultSet dbRes = null;
Statement is = null;
try {
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://420ito:9091/stores7:INFORMIXSERVER=ids1410;user=informix;password=passw;SQLIDEBUG=pp;");
is = conn.createStatement();
is.executeUpdate("drop table t2; create table t2 (c1 SET(integer not null) );");
java.util.HashSet arg1 = new HashSet();
Integer intObject;
int i;
for (i=1; i <= 3; i++)
{
intObject = new Integer(i);
arg1.add(intObject);
}
try {
//CallableStatement stmt = conn.prepareCall("{ CALL p2(?)}");
CallableStatement stmt = conn.prepareCall("{ CALL p2(?::SET(integer not null))}");
stmt.setObject(1, arg1);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM t2");
while (rs.next()) {
java.util.HashSet set = (HashSet) rs.getObject(1);
Iterator it = set.iterator();
Object obj;
i = 0;
while (it.hasNext())
{
obj = it.next();
System.out.println(" element[" + i + "] = " + obj.toString());
i++;
}
}
rs.close();
conn.close();
}
catch ( Exception e ) {
System.err.println(e);
e.printStackTrace();
}
}
}
D:\Infx\work\Java>javac t2.java
Note: t2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D:\Infx\work\Java>java t2
element[0] = 1
element[1] = 2
element[2] = 3
D:\Infx\work\Java>

Can't print output through loop, don't know how to print second table

Edit: anything would help. If anyone can tell me the process at least I'd appreciate it.
I'm trying to get my code to read for an access database that I made. In that database are 2 tables, one is Soccer_Team and the other is Soccer_Players. I'm having an issue figuring out how to have the field name show up in front of the actual data. When I run the code now I get this:
Name: Location: Home Stadium: FC Barcelona Spain Camp Nou
Name: Location: Home Stadium: FC Bayern Munich Germany Allianz
I want the "Name:" to be followed by the club name, and so on... I am not familiar with Java so I am a little confused here.
Also, I want to print the second table from my database through an SQL query, that has it display the above but with the player information printed under each row... I don't even know where to begin doing that. I'm not sure I'm explaining this well, so sorry if I'm confusing people.
Sorry if this is asking too much but I am pretty lost... Thanks for any help guys.
package msjavaaccessdb;
import java.sql.*;
import java.util.*;
public class MSjavaAccessDB {
/** Creates a new instance of databaseApplication */
public MSjavaAccessDB() {
}
/**
* #param args the command line arguments
*/
static String nameOfJdbcOdbcDriver =
"sun.jdbc.odbc.JdbcOdbcDriver";
// static String dataBaseNameDSN = "jdbc:odbc:myDataSource";
static String dataBaseNameDSN = "jdbc:odbc:myDataSource";
static String userName = "";
static String passwordForUser = "";
static Connection myConnectionRequest = null;
static Statement myStatementObject = null;
static ResultSet myResultTuples = null;
static ResultSetMetaData myResultTuplesMetaData = null;
static String queryToBeExecuted = "select * from Soccer_Team";
public static void main(String args[])
throws ClassNotFoundException {
try {
//Identify the driver to use
Class.forName(nameOfJdbcOdbcDriver);
//Attempt a connection to database...
Connection myConnectionRequest =
DriverManager.getConnection(
dataBaseNameDSN, userName, passwordForUser);
//Create a statement object, use its method to execute query
Statement myStatementObject =
myConnectionRequest.createStatement();
//Use statement object method to execute a query.
//Hold results in a resutl set...like a cursor
ResultSet myResultTuples = myStatementObject.executeQuery
(queryToBeExecuted);
//Call metadata to get the number of attributes
myResultTuplesMetaData = myResultTuples.getMetaData();
int numberOfAttributes =
myResultTuplesMetaData.getColumnCount();
System.out.println(Integer.toString(numberOfAttributes));
//For each row in result set, print ALL columns
for(int rowNum = 1; myResultTuples.next(); rowNum++) {
for (int i = 1; i <= numberOfAttributes; i++) {
if ( (i != 1) ) System.out.print (
myResultTuples.getString(i) + "\t");
else {//String xyz = myResultTuples.getString(1);
int xyz = Integer.parseInt( myResultTuples.getString(1));
System.out.print ("Name: ");
System.out.print ("Location: ");
System.out.print ("Home Stadium: ");
}
}
System.out.println("\n\n");
}
} // end of try block
//handle ALL exceptions to above database calls
catch (SQLException sqlError) {
System.out.println("Unexpected exception : " +
sqlError.toString() + ", sqlstate = " +
sqlError.getSQLState());
sqlError.printStackTrace();
}
} // end of main method of this class
} // end of the class
So I don't know how your datatable looks, but what i guess you want to do is print the column label and then the corresponding data value of the row.
for(int rowNum = 1; myResultTuples.next(); rowNum++) {
for (int i = 1; i <= numberOfAttributes; i++) {
//print column label
System.out.print(myResultTuplesMetaData.getColumnLabel(i) + ": ");
//print data value
System.out.print(myResultTuples.getString(i) + "\t");
}
System.out.println("\n\n");
//process SQl-Query about players and print out results in another for loop HERE
}
So for the second table you would have to do sth like SELECT * FROM table2 WHERE team IS (?) as a PreparedStatement and print out the results in another loop.
I can't get the error right now because I don't have access to NetBeans at this moment. I can update later when I am on my home computer. I'm not sure if what I did makes sense, because I don't exactly know what the rules of Java are... Hope this isn't stroke inducing.
package msjavaaccessdb;
import java.sql.*;
import java.util.*;
public class MSjavaAccessDB {
/** Creates a new instance of databaseApplication */
public MSjavaAccessDB() {
}
/**
* #param args the command line arguments
*/
static String nameOfJdbcOdbcDriver =
"sun.jdbc.odbc.JdbcOdbcDriver";
static String dataBaseNameDSN = "jdbc:odbc:myDataSource";
static String dataBaseNameDSN = "jdbc:odbc:myDataSource";
static String userName = "";
static String passwordForUser = "";
static Connection myConnectionRequest = null;
static Statement myStatementObject = null;
static ResultSet myResultTuples = null;
static ResultSetMetaData myResultTuplesMetaData = null;
static ResultSet ResultTuples = null;
static ResultSetMetaData ResultTuplesMetaData = null;
static String queryToBeExecuted = "select * from Soccer_Team";
static string secondQuery = "select * from Soccer_Player where team is (?)";
public static void main(String args[])
throws ClassNotFoundException {
try {
//Identify the driver to use
Class.forName(nameOfJdbcOdbcDriver);
//Attempt a connection to database...
Connection myConnectionRequest =
DriverManager.getConnection(
dataBaseNameDSN, userName, passwordForUser);
//Create a statement object, use its method to execute query
Statement myStatementObject =
myConnectionRequest.createStatement();
//Use statement object method to execute a query.
//Hold results in a resutl set...like a cursor
ResultSet myResultTuples = myStatementObject.executeQuery
(queryToBeExecuted);
ResultSet ResultTuples = myStatementObject.executeQuery
(secondQuery);
//Call metadata to get the number of attributes
myResultTuplesMetaData = myResultTuples.getMetaData();
int numberOfAttributes =
myResultTuplesMetaData.getColumnCount();
System.out.println(Integer.toString(numberOfAttributes));
ResultTuplesMetaData = ResultTuples.getMetaData();
int numOfAttributes =
ResultTuplesMetaData.getColumnCount();
System.out.println(Integer.toString(numOfAttributes));
//For each row in result set, print ALL columns
for(int rowNum = 1; myResultTuples.next(); rowNum++) {
for (int i = 1; i <= numberOfAttributes; i++) {
//print column label
System.out.print(myResultTuplesMetaData.getColumnLabel(i) + ": ");
//print data value
System.out.print(myResultTuples.getString(i) + "\t");
}
System.out.println("\n\n");
}
for(int rowNum = 1; ResultTuples.next(); rowNum++) {
for (int i = 1; i <= numOfAttributes; i++) {
//print column label
System.out.print(ResultTuplesMetaData.getColumnLabel(i) + ": ");
//print data value
System.out.print(ResultTuples.getString(i) + "\t");
}
System.out.println("\n\n");
}
} // end of try block
//handle ALL exceptions to above database calls
catch (SQLException sqlError) {
System.out.println("Unexpected exception : " +
sqlError.toString() + ", sqlstate = " +
sqlError.getSQLState());
sqlError.printStackTrace();
}
} // end of main method of this class
} // end of the class

Exporting database to csv file with java

so i found this code on the internet, basically what supposedly it can do is backup all the tables from a db, my question is on this line:
res = st.executeQuery("select * from xcms." + tableName);
i get the following excpetion exception: SQLException information
what does xcms. stands for? what else can i put here?
res = st.executeQuery("select * from " + tableName);
btw if i erase xcms. and put it like this ^, i can save only the first table not all the tables, thx
the sourcecode webpage:
https://gauravmutreja.wordpress.com/2011/10/13/exporting-your-database-to-csv-file-in-java/#comment-210
public static void main(String[] args) {
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "gg";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "";
FileWriter fw;
try {
Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'gg'");
List<String> tableNameList = new ArrayList<String>();
while (res.next()) {
tableNameList.add(res.getString(1));
}
String filename = "C:\\Users\\Angel Silva\\Documents";
for (String tableName : tableNameList) {
int k = 0;
int j = 1;
System.out.println(tableName);
List<String> columnsNameList = new ArrayList<String>();
res = st.executeQuery("select * from " + tableName);
int columnCount = getColumnCount(res);
try {
fw = new FileWriter("C:\\Users\\Angel Silva\\Documents\\popo1121.csv");
for (int i = 1; i <= columnCount; i++) {
fw.append(res.getMetaData().getColumnName(i));
fw.append(",");
}
fw.append(System.getProperty("line.separator"));
while (res.next()) {
for (int i = 1; i <= columnCount; i++) {
if (res.getObject(i) != null) {
String data = res.getObject(i).toString();
fw.append(data);
fw.append(",");
} else {
String data = "null";
fw.append(data);
fw.append(",");
}
}
fw.append(System.getProperty("line.separator"));
}
fw.flush();
fw.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
con.close();
} catch (ClassNotFoundException cnfe) {
System.err.println("Could not load JDBC driver");
cnfe.printStackTrace();
}catch (SQLException sqle) {System.err.println("SQLException information");}
}
public static int getRowCount(ResultSet res) throws SQLException {
res.last();
int numberOfRows = res.getRow();
res.beforeFirst();
return numberOfRows;
}
public static int getColumnCount(ResultSet res) throws SQLException {
return res.getMetaData().getColumnCount();
}
}
This is what I used:
public void sqlToCSV (String query, String filename){
log.info("creating csv file: " + filename);
try {
FileWriter fw = new FileWriter(filename + ".csv");
if(conn.isClosed()) st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
int cols = rs.getMetaData().getColumnCount();
for(int i = 1; i <= cols; i ++){
fw.append(rs.getMetaData().getColumnLabel(i));
if(i < cols) fw.append(',');
else fw.append('\n');
}
while (rs.next()) {
for(int i = 1; i <= cols; i ++){
fw.append(rs.getString(i));
if(i < cols) fw.append(',');
}
fw.append('\n');
}
fw.flush();
fw.close();
log.info("CSV File is created successfully.");
conn.close();
} catch (Exception e) {
log.fatal(e);
}
}
The xms stands for the Database name, in your Connection in the java program you already are establishing the connection to the Database:
(DriverManager.getConnection(url + db, user, pass);
The string db is the name of the DB to connect to.
So no need to have the xms. .just for example use this query:
"SELECT * FROM "+tableName+";"
This is executed in the database you are connected to, for example ggin your code.
For writting the CSV file chillyfacts.com/export-mysql-table-csv-file-using-java/ may help!
SELECT * FROM <MENTION_TABLE_NAME_HERE> INTO OUTFILE <FILE_NAME> FIELDS TERMINATED BY ',';
Example :
SELECT * FROM topic INTO OUTFILE 'D:\5.csv' FIELDS TERMINATED BY ',';
use opencsv dependency to export SQL data to CSV using minimal lines of code.
import com.opencsv.CSVWriter;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class CsvWriter {
public static void main(String[] args) throws Exception {
CSVWriter writer = new CSVWriter(new FileWriter("filename.csv"), '\t');
Boolean includeHeaders = true;
Statement statement = null;
ResultSet myResultSet = null;
Connection connection = null;
try {
connection = //make database connection here
if (connection != null) {
statement = connection.createStatement();
myResultSet = statement.executeQuery("your sql query goes here");
writer.writeAll(myResultSet, includeHeaders);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}

Fail to convert to internal representation JDBC

Ok so this is my code
public static ArrayList getMaterialerFraOrdreNr(String s_date, String e_date) throws SQLException, InterruptedException {
int tal = 0;
ArrayList nameOfColumns = getNameOfColumns(); // name of columns
ArrayList orderNumber = getOrdre_Nr_FromDB(s_date, e_date); // order number
//første loop kører gennem number of columns
//anden loop kører gennem name of column
ResultSet rs = null;
Connection con = null;
try {
Class.forName(DB.driver);
con = DriverManager.getConnection(DB.URL, DB.ID, DB.PW);
for (int i = 1; i < orderNumber.size(); i++) {
for (int j = 1; j < nameOfColumns.size(); j++) {
String nameOfColum = (String) nameOfColumns.get(i);
int orderNr = (Integer) orderNumber.get(j);
System.out.println("orderNr " + orderNr);
//SELECT v1001 FROM ORDRE_spec WHERE ordre_nr = 1;
String query = "SELECT ? AS ans FROM ordre_spec WHERE ordre_nr = ?";
PreparedStatement prest = con.prepareStatement(query);
prest.setString(1, nameOfColum);
prest.setInt(2, orderNr);
System.out.println("orderNr " + orderNr);
System.out.println("nameOfColum = " + nameOfColum);
rs = prest.executeQuery();
if(rs.next()){
tal = rs.getInt("ans");
MaterialeNum.add(tal);
System.out.println("materiale num = " + MaterialeNum);
}
}
}
} catch (ClassNotFoundException | SQLException ee) {
System.out.println("fail og der er så her");
System.err.println(ee);
} finally {
con.close();
}
System.out.println(kundeNum.toString());
return kundeNum;
}
public static void main(String[] args) throws SQLException, InterruptedException {
NewClass.getMaterialerFraOrdreNr("1990-10-10", "2020-10-10");
}
And my problem is that I'm getting a java.sql.SQLException: Fail to convert to internal representation
I really cant see what the error should be.. plz help if you can see the error :)
String query = "SELECT ? AS ans FROM ordre_spec WHERE ordre_nr = ?";
You cannot parameterize column names. You can only parameterize column values.
Basically you need to do:
String query = "SELECT " + nameOfColum + " AS ans FROM ordre_spec WHERE ordre_nr = ?";
Keep in mind that this is prone to SQL injection if nameOfColum is controllable by enduser. If this is indeed the case, you may want to perform string matching on e.g. \w+ before continuing.

changing Set<String> values from database to string values

How do i make my program read a Set value from the database one word by one word.
import java.util.*;
import java.sql.*;
public class SetProblem {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
Set<String> nums = new HashSet<>();
nums.add("1");
nums.add("2");
try
{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:src/database/set.db");
st = con.createStatement();
//st.execute("create table data(word, synonyms);");
//st.executeUpdate("insert into data values('figure', '"+nums+"');");
rs = st.executeQuery("select * from data;");
Set<String> set = new TreeSet<>();
while(rs.next())
{
set.add(rs.getString(2));
}
for(String s:set)
{
System.out.print(s + "");
}
}
catch(ClassNotFoundException e)
{
System.out.println("Driver not found");
}
catch(SQLException s)
{
System.out.println("wrong sql command");
}
}
}
my problem is that it prints [1, 2] instead of
1
2
which i want. How can i achieve this?
You're inserting one row, but what you want (I think) is to insert two rows. You see [1, 2] because it is exactly what you're inserting in the second column (you're forcing a nums.toString()).
Here the code I think you were looking for:
//...
Set<String> nums = new HashSet<>();
nums.add("1");
nums.add("2");
try
{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:src/database/set.db");
st = con.createStatement();
//st.execute("create table data(word, synonyms);");
//for(String i: nums) //HERE YOU NEED TO CYCLE
// st.executeUpdate("insert into data values('figure', '"+i+"');");
rs = st.executeQuery("select * from data;");
Set<String> set = new TreeSet<>();
while(rs.next())
{
set.add(rs.getString(2));
}
for(String s:set)
{
System.out.print(s + "");
}
}
//...

Categories