Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

It goes something like:
***
from t1 in db.Table1
join t2 in db.Table2 on t1.field equals t2.field
select new { t1.field2, t2.field3}
***
It would be nice to have sensible names and fields for your tables for a better example. :)

Update

I think for your query this might be more appropriate:
***
var dealercontacts = from contact in DealerContact
join dealer in Dealer on contact.DealerId equals dealer.ID
select contact;
***
Since you are looking for the contacts, not the dealers.
3 years ago
In Oracle 12c onward you could do something like,
***
CREATE TABLE MAPS
(
MAP_ID INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) NOT NULL,
MAP_NAME VARCHAR(24) NOT NULL,
UNIQUE (MAP_ID, MAP_NAME)
);
And in Oracle (Pre 12c).

-- create table
CREATE TABLE MAPS
(
MAP_ID INTEGER NOT NULL ,
MAP_NAME VARCHAR(24) NOT NULL,
UNIQUE (MAP_ID, MAP_NAME)
);
***
-- create sequence
***
CREATE SEQUENCE MAPS_SEQ;

-- create tigger using the sequence
CREATE OR REPLACE TRIGGER MAPS_TRG
BEFORE INSERT ON MAPS
FOR EACH ROW
WHEN (new.MAP_ID IS NULL)
BEGIN
SELECT MAPS_SEQ.NEXTVAL
INTO :new.MAP_ID
FROM dual;
END;
/
***
3 years ago
If you want to keep the row with the lowest id value:
***
DELETE FROM NAMES
WHERE id NOT IN (SELECT *
FROM (SELECT MIN(n.id)
FROM NAMES n
GROUP BY n.name) x)
***
If you want the id value that is the highest:
***
DELETE FROM NAMES
WHERE id NOT IN (SELECT *
FROM (SELECT MAX(n.id)
FROM NAMES n
GROUP BY n.name) x)
***
The subquery in a subquery is necessary for MySQL, or you'll get a 1093 error.
3 years ago
SELECT DISTINCT a.MovieName
FROM MovieList a
INNER JOIN CategoryList b
ON a.ID = b.MovieID
WHERE b.CategoryName = 'Comedy' AND
b.CategoryName = 'Romance'
3 years ago
You don't need to use a ScrollView actually.

Just set the
***
android:scrollbars = "vertical"
***
properties of your TextView in your layout's xml file.

Then use:
***
yourTextView.setMovementMethod(new ScrollingMovementMethod());
***

in your code.
3 years ago
You can send serializable object through intent
***
// send where details is object
ClassName details = new ClassName();
Intent i = new Intent(context, EditActivity.class);
i.putExtra("Editing", details);
startActivity(i);


//receive
ClassName model = (ClassName) getIntent().getSerializableExtra("Editing");

And

Class ClassName implements Serializable {
}
***
3 years ago
The clearfix allows a container to wrap its floated children. Without a clearfix or equivalent styling, a container does not wrap around its floated children and collapses, just as if its floated children were positioned absolutely.

There are several versions of the clearfix, with Nicolas Gallagher and Thierry Koblentz as key authors.

If you want support for older browsers, it's best to use this clearfix :
***
.clearfix:before, .clearfix:after {
content: "";
display: table;
}
***

.clearfix:after {
clear: both;
}

.clearfix {
*zoom: 1;
}
***
In SCSS, you could use the following technique :
***
%clearfix {
&:before, &:after {
content:" ";
display:table;
}

&:after {
clear:both;
}

& {
*zoom:1;
}
}

#clearfixedelement {
@extend %clearfix;
}
***
If you don't care about supporting older browsers, there's a shorter version :
***
.clearfix:after {
content:"";
display:table;
clear:both;
}
***
3 years ago
StringBuilder is faster than StringBuffer because it's not synchronized.

Here's a simple benchmark test:
***
public class Main {
public static void main(String[] args) {
int N = 77777777;
long t;

{
StringBuffer sb = new StringBuffer();
t = System.currentTimeMillis();
for (int i = N; i --> 0 ;) {
sb.append("");
}
System.out.println(System.currentTimeMillis() - t);
}

{
StringBuilder sb = new StringBuilder();
t = System.currentTimeMillis();
for (int i = N; i > 0 ; i--) {
sb.append("");
}
System.out.println(System.currentTimeMillis() - t);
}
}
}
***
A test run gives the numbers of 2241 ms for StringBuffer vs 753 ms for StringBuilder.
3 years ago
java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.
3 years ago
If you're willing to use an external library, check out Apache Commons IO (200KB JAR). It contains an org.apache.commons.io.FileUtils.readFileToString() method that allows you to read an entire File into a String with one line of code.

Example:
***
import java.io.*;
import java.nio.charset.*;
import org.apache.commons.io.*;

public String readFile() throws IOException {
File file = new File("data.txt");
return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
}
***
3 years ago
***
for (Iterator i = someIterable.iterator(); i.hasNext();) {
String item = i.next();
System.out.println(item);
}
***
Note that if you need to use i.remove(); in your loop, or access the actual iterator in some way, you cannot use the for ( : ) idiom, since the actual iterator is merely inferred.

As was noted by Denis Bueno, this code works for any object that implements the Iterable interface.

Also, if the right-hand side of the for (:) idiom is an array rather than an Iterable object, the internal code uses an int index counter and checks against array.length instead.
3 years ago
If your source code name is HelloWorld.java, your compiled code will be HelloWorld.class.

You will get that error if you call it using:
***
java HelloWorld.class
***
Instead, use this:
***
java HelloWorld
***
3 years ago