Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java Sqlite how to print a.rowname

I asked myself how I print a.rowname in Java with jbdc sqlite.
Or did I take the wrong solution to fetch all the Selected data?

I tried this:

String vergleichVon ="DB_18_12_2021_02h13m05s";
String vergleichBis ="DB_18_12_2021_08h28m19s";

Connection connection = null;
try
{
    //Connect to Database
    connection = DriverManager.getConnection("jdbc:sqlite:"+dataBasePath+"");
    Statement c = connection.createStatement();
    c.setQueryTimeout(30);  // set timeout to 30 sec.

    ResultSet rs = c.executeQuery("SELECT a.name, a.pt, b.pt, a.sz, a.bd"+
                                    "FROM "+vergleichVon+" AS a, "+vergleichBis+" AS b "+
                                    "WHERE a.name= b.name AND a.pt>'1000' AND b.pt>='1000' AND a.pt!='n/v' AND b.pt!='n/v' "+
                                    "ORDER BY a.pt DESC");
    while(rs.next())
    {
      // read the result set
      System.out.print("nameA = " + rs.getString("a.name"));
      System.out.print(" ");
      System.out.println("ptB = " + rs.getString("b.pt"));
    }
}

And I get this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

no such column: 'a.name' 

In Python it works kind of like this. I can later just get the Selected data from the array:

c.execute('''SELECT a.name, a.pt, b.pt, a.sz, a.bd
          FROM '''+vergleich_von+''' AS a, '''+vergleich_bis+''' AS b
          WHERE a.name= b.name AND a.pt>'1000' AND b.pt>='1000' AND a.pt!='n/v' AND b.pt!='n/v'
          ORDER BY a.pt DESC''')
array = c.fetchall()

>Solution :

You do not select a.spieler

try:

ResultSet rs = c.executeQuery("SELECT a.name as spieler, a.pt, b.pt as bpt, a.sz, a.bd"+
                                "FROM "+vergleichVon+" AS a, "+vergleichBis+" AS b "+
                                "WHERE a.name= b.name AND a.pt>'1000' AND b.pt>='1000' AND a.pt!='n/v' AND b.pt!='n/v' "+
                                "ORDER BY a.pt DESC");
while(rs.next())
{
  // read the result set
  System.out.print("nameA = " + rs.getString("spieler"));
  System.out.print(" ");
  System.out.println("ptB = " + rs.getString("bpt"));
}

Update after question edit
Use aliases for the columns without dots:

ResultSet rs = c.executeQuery("SELECT a.name as name, a.pt as apt, b.pt as bpt, a.sz as asz, a.bd as adb"+
                                "FROM "+vergleichVon+" AS a, "+vergleichBis+" AS b "+
                                "WHERE a.name= b.name AND a.pt>'1000' AND b.pt>='1000' AND a.pt!='n/v' AND b.pt!='n/v' "+
                                "ORDER BY a.pt DESC");
while(rs.next())
{
  // read the result set
  System.out.print("nameA = " + rs.getString("name"));
  System.out.print(" ");
  System.out.println("ptB = " + rs.getString("bpt"));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading